This guide explains how to deploy ZenServer on Val Town, which has specific restrictions on filesystem access.
Val Town doesn't allow filesystem operations for security reasons. This means:
- No reading
.envfiles - No writing log files
- No reading JSON files from disk
We've created Val Town-compatible versions of the core modules:
main-valtown.ts- Entry point for Val Townsrc/config/env-loader-valtown.ts- Environment loader that skips file operationssrc/utils/logger-valtown.ts- Console-only logger (no file writes)src/utils/openApiLoader-valtown.ts- Uses embedded OpenAPI specsrc/utils/embeddedOpenApiSpec.ts- OpenAPI spec as JavaScript objectsrc/gateway/apiGateway-valtown.ts- API Gateway using Val Town modules
In your Val Town settings, set these environment variables:
PAYMENT_USERNAME=your_zenpay_username
PAYMENT_PASSWORD=your_zenpay_password
TURNSTILE_SECRET_KEY=your_cloudflare_turnstile_key
ALLOWED_ORIGINS=https://yourdomain.com,https://anotherdomain.com
LOG_LEVEL=INFO
WEBHOOK_SECRET=your_webhook_secret
SESSION_SECRET=your_session_secret
APP_ENV=prod
VALTOWN_TOKEN=your_valtown_token
ADMIN_API_KEY=your_admin_api_key
Create a new HTTP Val and use this code:
// Import the Val Town compatible version
import zenServer from "https://esm.town/v/yourusername/ZenServer-valtown";
// Export the default handler
export default zenServer;
Or if you're copying the entire codebase:
// Use the Val Town compatible main file
import "./main-valtown.ts";
If copying files to Val Town, update these imports in existing files:
// In files that import env-loader
import { loadDevEnvironment } from "./src/config/env-loader-valtown.ts";
// In files that import logger
import { logger, logInfo, logError } from "./src/utils/logger-valtown.ts";
// In files that import openApiLoader
import { createOpenAPILoader } from "./src/utils/openApiLoader-valtown.ts";
// In main entry point
import app from "./src/gateway/apiGateway-valtown.ts";
After deploying, test these endpoints:
GET /- Should return "ZenServer is running on Val Town!"GET /health- Should return "OK"GET /openapi.json- Should return the OpenAPI specificationGET /api/v1/tours- Should return the list of tours
- No File System Access: All file operations are removed
- Console Logging Only: No log files are created
- Embedded OpenAPI Spec: The spec is included as a JavaScript object
- Environment Variables: Must be set via Val Town's UI, not
.envfiles
-
"NotCapable" Errors: These indicate filesystem access attempts. Use the Val Town compatible versions.
-
Missing Environment Variables: Set all required variables in Val Town's environment settings.
-
Import Errors: Ensure you're using the
-valtownversions of modules.
To enable debug mode on Val Town:
- Set
DEBUG_MODE=truein environment variables - Debug output will appear in Val Town's console logs
- Rate Limiting: In-memory rate limiting resets when Val restarts
- Session Storage: Sessions are temporary and reset on Val restart
- Database: Ensure your SQLite database is properly configured for Val Town
For issues specific to Val Town deployment, check:
- Val Town documentation: https://docs.val.town
- ZenServer Val Town issues: [create an issue with "valtown" tag]