diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 061ea50609..dcaa91c9fc 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -4,6 +4,7 @@ import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; +import { PathOrFileDescriptor, readFileSync } from 'node:fs'; import ms from 'ms'; import Koa from 'koa'; import Router from '@koa/router'; @@ -74,6 +75,11 @@ app.use(views(_dirname + '/views', { options: { version: config.version, config, + ...(process.env.NODE_ENV !== 'production' ? { + process, + _dirname, + readFileSync: (path: PathOrFileDescriptor): string => readFileSync(path, 'utf8'), + } : {}), }, })); diff --git a/packages/backend/src/server/web/views/base.pug b/packages/backend/src/server/web/views/base.pug index a0fe55289f..c2ae39c1fd 100644 --- a/packages/backend/src/server/web/views/base.pug +++ b/packages/backend/src/server/web/views/base.pug @@ -50,9 +50,16 @@ html style include ../style.css - script. - var VERSION = "#{version}"; - var CLIENT_ENTRY = "#{config.clientEntry}"; + if process.env.NODE_ENV === 'production' + script. + var VERSION = "#{version}"; + var CLIENT_ENTRY = "#{config.clientEntry}"; + else + - + const clientEntry = JSON.parse(readFileSync(`${_dirname}/../../../../../built/_client_dist_/manifest.json`, 'utf-8'))['src/init.ts'].file.replace(/^_client_dist_\//, ''); + script. + var VERSION = "#{version}"; + var CLIENT_ENTRY = "#{clientEntry}"; script include ../boot.js