From 1f263a7df5f7bbd726ada61021713361119c4fcf Mon Sep 17 00:00:00 2001 From: Evan Tahler Date: Sat, 12 Oct 2024 20:36:21 -0700 Subject: [PATCH] APPLICATION_URL --- .env | 2 +- backend/.env.example | 2 -- backend/config/server/web.ts | 4 ++-- backend/servers/web.ts | 20 -------------------- caddyfile | 2 +- render.yaml | 6 ++---- 6 files changed, 6 insertions(+), 30 deletions(-) diff --git a/.env b/.env index 24ee61e..82e6f03 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ # This is the port for the proxy server to listen on - this is the 'front door' for the application PORT=3000 -WEB_SERVER_APPLICATION_URL="http://localhost:3000" +APPLICATION_URL="http://localhost:3000" diff --git a/backend/.env.example b/backend/.env.example index 07c0077..3fbe707 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -11,8 +11,6 @@ WEB_SERVER_ENABLED=true WEB_SERVER_PORT=8080 WEB_SERVER_PORT_TEST=8090 WEB_SERVER_HOST=localhost -WEB_SERVER_APPLICATION_URL="http://localhost:3000" -WEB_SERVER_APPLICATION_URL_TEST="http://localhost:8090" WEB_SERVER_API_ROUTE="/api" SESSION_TTL=86400000 diff --git a/backend/config/server/web.ts b/backend/config/server/web.ts index 45031c1..9fb5f62 100644 --- a/backend/config/server/web.ts +++ b/backend/config/server/web.ts @@ -1,14 +1,14 @@ import { loadFromEnvIfSet } from "../../util/config"; const port = await loadFromEnvIfSet("WEB_SERVER_PORT", 8080); -const host = await loadFromEnvIfSet("WEB_SERVER_HOST", "0.0.0.0"); +const host = await loadFromEnvIfSet("WEB_SERVER_HOST", "localhost"); export const configServerWeb = { enabled: await loadFromEnvIfSet("WEB_SERVER_ENABLED", true), port, host, applicationUrl: await loadFromEnvIfSet( - "WEB_SERVER_APPLICATION_URL", + "APPLICATION_URL", // NOte - this is loaded by foreman, injected by the top-level env `http://${host}:${port}`, ), apiRoute: await loadFromEnvIfSet("WEB_SERVER_API_ROUTE", "/api"), diff --git a/backend/servers/web.ts b/backend/servers/web.ts index 8b59594..86c4128 100644 --- a/backend/servers/web.ts +++ b/backend/servers/web.ts @@ -79,11 +79,6 @@ export class WebServer extends Server> { req: Request, server: ReturnType, ) { - const isCorrectUrl = checkApplicationUrl(req); - if (!isCorrectUrl) { - return Response.redirect(config.server.web.applicationUrl, 302); - } - const ip = server.requestIP(req)?.address || "unknown-IP"; const headers = req.headers; const cookies = cookie.parse(req.headers.get("cookie") ?? ""); @@ -391,19 +386,4 @@ function buildErrorPayload(error: TypedError) { }; } -function checkApplicationUrl(req: Request) { - if (config.server.web.applicationUrl.length > 3) { - const hostHeader = req.headers.get("host"); - const forwardHeader = req.headers.get("x-forwarded-proto"); - - const requestHost = forwardHeader - ? forwardHeader + "://" + hostHeader - : "http://" + hostHeader; - - if (config.server.web.applicationUrl !== requestHost) return false; - } - - return true; -} - const EOL = "\r\n"; diff --git a/caddyfile b/caddyfile index 6114524..de9abe5 100644 --- a/caddyfile +++ b/caddyfile @@ -1,4 +1,4 @@ -:{$PORT}, {$WEB_SERVER_APPLICATION_URL} { +:{$PORT}, {$APPLICATION_URL} { route /api/* { reverse_proxy localhost:8080 } diff --git a/render.yaml b/render.yaml index a5f253e..c26a09e 100644 --- a/render.yaml +++ b/render.yaml @@ -26,11 +26,9 @@ services: value: "true" - key: LOG_INCLUDE_TIMESTAMPS value: "false" - - key: NEXT_DEV - value: "false" - # - key: WEB_SERVER_APPLICATION_URL + # - key: APPLICATION_URL # value: "false" - - key: WEB_SERVER_PORT + - key: PORT value: 10000 - key: NODE_ENV value: production