capability to run server in dev using static frontend/admin

Massimo Melina committed Feb 7, 2022 at 12:42 UTC 657b65fab18cdb1a82e3c9cd37c09b1a669d5ce7
1 file changed +5 -2
src/serveFrontend.ts
+5 -2
@@ -26,8 +26,11 @@ function serveProxyFrontend(port?: string) { // used for development
26 }
27 }
28
29 +// in case of dev env we have our static files within the 'dist' folder'
30 +const DEV_STATIC = process.env.DEV ? 'dist/' : ''
31 +
32 const serveStaticFrontend : Koa.Middleware = async (ctx, next) => {
30 - const BASE = 'frontend/'
33 + const BASE = DEV_STATIC + 'frontend/'
34 let { path, method } = ctx
35 if (method === 'OPTIONS') {
36 ctx.status = NO_CONTENT
@@ -64,7 +67,7 @@ function serveAdminProxy(port?: string) { // used for development
67
68 const serveAdminStatic : Koa.Middleware = async (ctx, next) => {
69 const fullPath = 'admin' + (ctx.path.includes('.') ? ctx.path : '/index.html');
67 - return serveFile(fullPath, 'auto')(ctx, next)
70 + return serveFile(DEV_STATIC + fullPath, 'auto')(ctx, next)
71 }
72
73 async function treatIndex(ctx: Koa.Context, body: string) {