Skip to content

Commit

Permalink
APPLICATION_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Oct 13, 2024
1 parent 45b5085 commit 1f263a7
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backend/config/server/web.ts
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
20 changes: 0 additions & 20 deletions backend/servers/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ export class WebServer extends Server<ReturnType<typeof Bun.serve>> {
req: Request,
server: ReturnType<typeof Bun.serve>,
) {
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") ?? "");
Expand Down Expand Up @@ -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";
2 changes: 1 addition & 1 deletion caddyfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:{$PORT}, {$WEB_SERVER_APPLICATION_URL} {
:{$PORT}, {$APPLICATION_URL} {
route /api/* {
reverse_proxy localhost:8080
}
Expand Down
6 changes: 2 additions & 4 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f263a7

Please sign in to comment.