From da856261f3f5c6ad0a18ff10d31c94e6edc61cef Mon Sep 17 00:00:00 2001 From: hwhung Date: Wed, 6 May 2026 00:04:11 +0800 Subject: [PATCH] Simplify Replit deployment --- .replit | 6 ++++++ readme.md | 38 ++++++++++++++++++++++++++++---------- replit.md | 24 ++++++++++++++++++++++-- setup.md | 34 ++++++++++++++++++++++++++++++++++ src/lib/config.ts | 30 ++++++++++++++++++++++-------- 5 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 .replit create mode 100644 setup.md diff --git a/.replit b/.replit new file mode 100644 index 0000000..9f8d8b7 --- /dev/null +++ b/.replit @@ -0,0 +1,6 @@ +run = "pnpm dev" +onBoot = "pnpm install --ignore-workspace" + +[deployment] +build = "pnpm install --ignore-workspace && pnpm run build" +run = "pnpm start" diff --git a/readme.md b/readme.md index 55ef7a7..d22cc0f 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,20 @@ This app is already prepared for one-shot deployment. Follow these commands exac Do not add this repo to a parent workspace. Do not move it into `artifacts/`. Do not edit source files. Do not edit `package.json`. Do not create `config.json` or a `/tmp` config file for deployment. Do not inspect or free unrelated ports. +## Replit + +The repo includes `.replit`, so after import the Run button starts the app with: + +```bash +pnpm dev +``` + +The `.replit` `onBoot` command installs dependencies with: + +```bash +pnpm install --ignore-workspace +``` + ## Install Run from this repository root: @@ -16,37 +30,41 @@ Use the available `pnpm`. This repo intentionally has no `packageManager` pin. ## Start -Without Replit AI Integrations: - ```bash pnpm dev ``` -With Replit AI Integrations: +When Replit AI Integrations are provisioned, the app reads these variables automatically: + +- `AI_INTEGRATIONS_OPENAI_BASE_URL` +- `AI_INTEGRATIONS_OPENAI_API_KEY` +- `AI_INTEGRATIONS_ANTHROPIC_BASE_URL` +- `AI_INTEGRATIONS_ANTHROPIC_API_KEY` + +Provider CLI flags are still supported for manual overrides: ```bash pnpm dev -- \ - --host 0.0.0.0 \ - --port 3000 \ - --proxy-api-key dev-proxy-key \ --openai-base-url "" \ --openai-api-key "" \ --anthropic-base-url "" \ --anthropic-api-key "" ``` -The provider flags above are implemented. Do not verify them by reading source first. - Use Replit AI Integrations endpoints only. Never use public official provider endpoints. Do not print provider tokens. -If the process does not stay alive after the shell exits, create the smallest background workflow that runs the same `pnpm dev ...` command from this repository root. - ## Defaults - host: `0.0.0.0` - port: `3000` - bearer token: `dev-proxy-key` +These can be overridden with CLI flags or environment variables: + +- `--host` or `HOST` +- `--port` or `PORT` +- `--proxy-api-key` or `PROXY_API_KEY` + ## Verify ```bash diff --git a/replit.md b/replit.md index 499a301..10a7c27 100644 --- a/replit.md +++ b/replit.md @@ -2,7 +2,7 @@ ## Overview -Standalone TypeScript API server with CLI-only deployment configuration. +Standalone TypeScript API server with Replit run and deployment configuration. ## Stack @@ -14,7 +14,14 @@ Standalone TypeScript API server with CLI-only deployment configuration. ## Provider Endpoints -Use Replit AI Integrations endpoints through CLI flags: +Use Replit AI Integrations endpoints. The app reads these environment variables automatically: + +- `AI_INTEGRATIONS_OPENAI_BASE_URL` +- `AI_INTEGRATIONS_OPENAI_API_KEY` +- `AI_INTEGRATIONS_ANTHROPIC_BASE_URL` +- `AI_INTEGRATIONS_ANTHROPIC_API_KEY` + +CLI flags are still available for manual overrides: - `--openai-base-url` - `--openai-api-key` @@ -31,6 +38,19 @@ Never use public official provider endpoints. - `pnpm run build` — typecheck and build `dist/index.mjs` - `pnpm start` — run the built server +## Replit Configuration + +- `.replit` `run` uses `pnpm dev` +- `.replit` `onBoot` uses `pnpm install --ignore-workspace` +- deployment build uses `pnpm install --ignore-workspace && pnpm run build` +- deployment run uses `pnpm start` + +## Server Overrides + +- `--host` or `HOST` +- `--port` or `PORT` +- `--proxy-api-key` or `PROXY_API_KEY` + ## Routes - `/` and `/dashboard` — static model dashboard diff --git a/setup.md b/setup.md new file mode 100644 index 0000000..adc6cbd --- /dev/null +++ b/setup.md @@ -0,0 +1,34 @@ +Clone and run https://git.komnenos.me/springfw/random-proxy in ./random-proxy. + +Goal: get the app running once, with Replit AI Integrations wired, on port 3000. + +Do not: +- add it to a parent workspace +- move it into artifacts/ +- modify source files +- edit package.json +- create config.json or /tmp config files +- inspect/free unrelated ports +- use nohup/setsid/background shell tricks +- run chat-completion smoke tests unless asked + +Steps: + +1. Clone into ./random-proxy. + +2. Provision/use Replit AI Integrations for: + - OpenAI + - Anthropic + +3. Open ./random-proxy and use the configured Replit Run button. + +4. Wait briefly, then verify: + + curl -s http://localhost:3000/api/healthz + curl -s http://localhost:3000/dashboard | head + curl -s -H "Authorization: Bearer dev-proxy-key" http://localhost:3000/v1/models + +Report only: +- local URL +- whether OpenAI and Anthropic AI Integrations were wired +- verification results diff --git a/src/lib/config.ts b/src/lib/config.ts index c047b59..4e4d7b7 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -55,31 +55,45 @@ function argFlag(name: string): boolean { return process.argv.includes(`--${name}`); } +function envValue(name: string): string | undefined { + const value = process.env[name]; + return value && value.length > 0 ? value : undefined; +} + function applyArgOverrides(base: AppConfig): AppConfig { - const rawPort = argValue("port"); + const rawPort = argValue("port") ?? envValue("PORT"); const port = rawPort === undefined ? base.server.port : Number(rawPort); if (!Number.isInteger(port) || port <= 0) { - throw new Error(`Invalid CLI value "--port": ${rawPort}`); + throw new Error(`Invalid port value: ${rawPort}`); } + const host = argValue("host") ?? envValue("HOST") ?? base.server.host; + const proxyApiKey = argValue("proxy-api-key") ?? envValue("PROXY_API_KEY") ?? base.proxy.apiKey; + const openaiBaseURL = argValue("openai-base-url") ?? envValue("AI_INTEGRATIONS_OPENAI_BASE_URL"); + const openaiApiKey = argValue("openai-api-key") ?? envValue("AI_INTEGRATIONS_OPENAI_API_KEY"); + const anthropicBaseURL = + argValue("anthropic-base-url") ?? envValue("AI_INTEGRATIONS_ANTHROPIC_BASE_URL"); + const anthropicApiKey = + argValue("anthropic-api-key") ?? envValue("AI_INTEGRATIONS_ANTHROPIC_API_KEY"); + return { server: { - host: argValue("host") ?? base.server.host, + host, port, }, proxy: { - apiKey: argValue("proxy-api-key") ?? base.proxy.apiKey, + apiKey: proxyApiKey, }, providers: { openai: { ...base.providers.openai, - ...(argValue("openai-base-url") ? { baseURL: argValue("openai-base-url") } : {}), - ...(argValue("openai-api-key") ? { apiKey: argValue("openai-api-key") } : {}), + ...(openaiBaseURL ? { baseURL: openaiBaseURL } : {}), + ...(openaiApiKey ? { apiKey: openaiApiKey } : {}), }, anthropic: { ...base.providers.anthropic, - ...(argValue("anthropic-base-url") ? { baseURL: argValue("anthropic-base-url") } : {}), - ...(argValue("anthropic-api-key") ? { apiKey: argValue("anthropic-api-key") } : {}), + ...(anthropicBaseURL ? { baseURL: anthropicBaseURL } : {}), + ...(anthropicApiKey ? { apiKey: anthropicApiKey } : {}), }, }, logging: {