From f65299cb361e7e600eae99e6ee1e241ee97f6263 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 31 Aug 2026 09:28:34 +0200 Subject: [PATCH] fix(developer): use path not dependent on pwd for starting Server Fixes: #12165 Test-bot: skip --- developer/src/server/src/environment.ts | 20 ++++++++++++++++++++ developer/src/server/src/routes.ts | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/developer/src/server/src/environment.ts b/developer/src/server/src/environment.ts index f3e0566024..9b9659ba4a 100644 --- a/developer/src/server/src/environment.ts +++ b/developer/src/server/src/environment.ts @@ -1,5 +1,25 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + * + * Environmental variables and paths + */ +import path from 'node:path'; import { extractVersionData } from './version-data.js'; // TODO: environment should be just KEYMAN_VERSION import KEYMAN_VERSION from "@keymanapp/keyman-version"; export const environment = extractVersionData(KEYMAN_VERSION.VERSION_WITH_TAG); + +/** + * @returns base path for the running server -- where index.js is stored + */ +export function serverBasePath() { + return path.join(import.meta.dirname, '../../build/src'); +} + +/** + * @returns path where the site public files can be found -- index.html + */ +export function serverSitePath() { + return path.join(serverBasePath(), 'site'); +} diff --git a/developer/src/server/src/routes.ts b/developer/src/server/src/routes.ts index acccf23402..4bb4386522 100644 --- a/developer/src/server/src/routes.ts +++ b/developer/src/server/src/routes.ts @@ -1,3 +1,8 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + * + * Setup URL routes for Keyman Developer Server + */ import * as express from 'express'; import * as ws from 'ws'; import * as multer from 'multer'; @@ -16,6 +21,7 @@ import { standardPaths } from './standardPaths.js'; import chalk from 'chalk'; import { shutdown } from './shutdown.js'; import { getOption } from './options.js'; +import { serverSitePath } from './environment.js'; export default function setupRoutes(app: express.Express, upload: multer.Multer, wsServer: ws.WebSocketServer, environment: Environment ) { @@ -51,7 +57,7 @@ export default function setupRoutes(app: express.Express, upload: multer.Multer, /* All routes */ - app.use('/', express.static('build/src/site')); + app.use('/', express.static(serverSitePath())); app.post('/upload', localhostOnly, upload.single('file'), (req, res, next) => { const name = req.file.originalname;