From 09ec432f16bab93eb6edd994cb388a641f345109 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 8 Nov 2023 22:58:45 +0800 Subject: [PATCH] refactor: add server url for serverStatus --- docker-compose.yml | 1 + src/server/router/serverStatus.ts | 3 ++- src/server/utils/env.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6adf136..6f82cfa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: JWT_SECRET: replace-me-with-a-random-string ALLOW_REGISTER: "false" ALLOW_OPENAPI: "true" + SERVER_URL: depends_on: - postgres restart: always diff --git a/src/server/router/serverStatus.ts b/src/server/router/serverStatus.ts index 884c363..918175c 100644 --- a/src/server/router/serverStatus.ts +++ b/src/server/router/serverStatus.ts @@ -3,6 +3,7 @@ import { body, header, param, validate } from '../middleware/validate'; import { recordServerStatus } from '../model/serverStatus'; import fs from 'fs-extra'; import path from 'path'; +import { env } from '../utils/env'; export const serverStatusRouter = Router(); @@ -34,7 +35,7 @@ serverStatusRouter.get( validate(param('workspaceId').isString()), async (req, res) => { const { workspaceId } = req.params; - const server = `${req.protocol}://${req.get('Host')}`; + const server = env.serverUrl || `${req.protocol}://${req.get('Host')}`; res .setHeader('Content-Type', 'text/plain') diff --git a/src/server/utils/env.ts b/src/server/utils/env.ts index cf6f826..ccc6e50 100644 --- a/src/server/utils/env.ts +++ b/src/server/utils/env.ts @@ -2,6 +2,7 @@ export const env = { allowRegister: checkEnvTrusty(process.env.ALLOW_REGISTER), allowOpenapi: checkEnvTrusty(process.env.ALLOW_OPENAPI), websiteId: process.env.WEBSITE_ID, + serverUrl: process.env.SERVER_URL, // example: https://tianji.example.com }; export function checkEnvTrusty(env: string | undefined): boolean {