diff --git a/.env.example b/.env.example index 62abbae..fb38cc6 100644 --- a/.env.example +++ b/.env.example @@ -14,6 +14,9 @@ NODE_ENV=production # The title displayed on the info page. # SERVER_TITLE=Coom Tunnel +# The route name used to proxy requests to APIs, relative to the Web site root. +# PROXY_ENDPOINT_ROUTE=/proxy + # Text model requests allowed per minute per user. # TEXT_MODEL_RATE_LIMIT=4 # Image model requests allowed per minute per user. @@ -37,10 +40,10 @@ NODE_ENV=production # Which model types users are allowed to access. # The following model families are recognized: -# turbo | gpt4 | gpt4-32k | gpt4-turbo | dall-e | claude | gemini-pro | mistral-tiny | mistral-small | mistral-medium | aws-claude | azure-turbo | azure-gpt4 | azure-gpt4-32k | azure-gpt4-turbo +# turbo | gpt4 | gpt4-32k | gpt4-turbo | dall-e | claude | gemini-pro | mistral-tiny | mistral-small | mistral-medium | mistral-large | aws-claude | azure-turbo | azure-gpt4 | azure-gpt4-32k | azure-gpt4-turbo # By default, all models are allowed except for 'dall-e'. To allow DALL-E image # generation, uncomment the line below and add 'dall-e' to the list. -# ALLOWED_MODEL_FAMILIES=turbo,gpt4,gpt4-32k,gpt4-turbo,claude,gemini-pro,mistral-tiny,mistral-small,mistral-medium,aws-claude,azure-turbo,azure-gpt4,azure-gpt4-32k,azure-gpt4-turbo +# ALLOWED_MODEL_FAMILIES=turbo,gpt4,gpt4-32k,gpt4-turbo,claude,gemini-pro,mistral-tiny,mistral-small,mistral-medium,mistral-large,aws-claude,azure-turbo,azure-gpt4,azure-gpt4-32k,azure-gpt4-turbo # URLs from which requests will be blocked. # BLOCKED_ORIGINS=reddit.com,9gag.com diff --git a/src/config.ts b/src/config.ts index fa8a1c5..24365df 100644 --- a/src/config.ts +++ b/src/config.ts @@ -249,6 +249,11 @@ type Config = { * risk. */ allowOpenAIToolUsage?: boolean; + /** + * Allows overriding the default proxy endpoint route. Defaults to /proxy. + * A leading slash is required. + */ + proxyEndpointRoute: string; }; // To change configs, create a file called .env in the root directory. @@ -342,6 +347,7 @@ export const config: Config = { staticServiceInfo: getEnvWithDefault("STATIC_SERVICE_INFO", false), trustedProxies: getEnvWithDefault("TRUSTED_PROXIES", 1), allowOpenAIToolUsage: getEnvWithDefault("ALLOW_OPENAI_TOOL_USAGE", false), + proxyEndpointRoute: getEnvWithDefault("PROXY_ENDPOINT_ROUTE", "/proxy"), } as const; function generateCookieSecret() { @@ -460,7 +466,8 @@ export const OMITTED_KEYS = [ "staticServiceInfo", "checkKeys", "allowedModelFamilies", - "trustedProxies" + "trustedProxies", + "proxyEndpointRoute", ] satisfies (keyof Config)[]; type OmitKeys = (typeof OMITTED_KEYS)[number]; diff --git a/src/info-page.ts b/src/info-page.ts index dadec19..85324d6 100644 --- a/src/info-page.ts +++ b/src/info-page.ts @@ -47,7 +47,7 @@ export const handleInfoPage = (req: Request, res: Response) => { ? getExternalUrlForHuggingfaceSpaceId(process.env.SPACE_ID) : req.protocol + "://" + req.get("host"); - const info = buildInfo(baseUrl + "/proxy"); + const info = buildInfo(baseUrl + config.proxyEndpointRoute); infoPageHtml = renderPage(info); infoPageLastUpdated = Date.now(); diff --git a/src/server.ts b/src/server.ts index fdd5235..2c3ac19 100644 --- a/src/server.ts +++ b/src/server.ts @@ -14,7 +14,6 @@ import { adminRouter } from "./admin/routes"; import { proxyRouter } from "./proxy/routes"; import { infoPageRouter } from "./info-page"; import { userRouter } from "./user/routes"; -import { buildInfo } from "./service-info"; import { logQueue } from "./shared/prompt-logging"; import { start as startRequestQueue } from "./proxy/queue"; import { init as initUserStore } from "./shared/users/user-store"; @@ -67,7 +66,7 @@ app.use(cors()); app.use(checkOrigin); app.use("/admin", adminRouter); -app.use("/proxy", proxyRouter); +app.use(config.proxyEndpointRoute, proxyRouter); app.use("/user", userRouter); if (config.staticServiceInfo) { app.get("/", (_req, res) => res.sendStatus(200));