refactor: add server url for serverStatus

This commit is contained in:
moonrailgun 2023-11-08 22:58:45 +08:00
parent 7d7519203c
commit 09ec432f16
3 changed files with 4 additions and 1 deletions

View File

@ -9,6 +9,7 @@ services:
JWT_SECRET: replace-me-with-a-random-string JWT_SECRET: replace-me-with-a-random-string
ALLOW_REGISTER: "false" ALLOW_REGISTER: "false"
ALLOW_OPENAPI: "true" ALLOW_OPENAPI: "true"
SERVER_URL:
depends_on: depends_on:
- postgres - postgres
restart: always restart: always

View File

@ -3,6 +3,7 @@ import { body, header, param, validate } from '../middleware/validate';
import { recordServerStatus } from '../model/serverStatus'; import { recordServerStatus } from '../model/serverStatus';
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import { env } from '../utils/env';
export const serverStatusRouter = Router(); export const serverStatusRouter = Router();
@ -34,7 +35,7 @@ serverStatusRouter.get(
validate(param('workspaceId').isString()), validate(param('workspaceId').isString()),
async (req, res) => { async (req, res) => {
const { workspaceId } = req.params; const { workspaceId } = req.params;
const server = `${req.protocol}://${req.get('Host')}`; const server = env.serverUrl || `${req.protocol}://${req.get('Host')}`;
res res
.setHeader('Content-Type', 'text/plain') .setHeader('Content-Type', 'text/plain')

View File

@ -2,6 +2,7 @@ export const env = {
allowRegister: checkEnvTrusty(process.env.ALLOW_REGISTER), allowRegister: checkEnvTrusty(process.env.ALLOW_REGISTER),
allowOpenapi: checkEnvTrusty(process.env.ALLOW_OPENAPI), allowOpenapi: checkEnvTrusty(process.env.ALLOW_OPENAPI),
websiteId: process.env.WEBSITE_ID, websiteId: process.env.WEBSITE_ID,
serverUrl: process.env.SERVER_URL, // example: https://tianji.example.com
}; };
export function checkEnvTrusty(env: string | undefined): boolean { export function checkEnvTrusty(env: string | undefined): boolean {