From 64cddf127a0180ce31977c7fadc2967adb499344 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 2 Feb 2024 16:31:45 +0800 Subject: [PATCH] feat: add local dev dashboard debug option Signed-off-by: Innei --- apps/core/src/bootstrap.ts | 3 ++ .../modules/pageproxy/pageproxy.controller.ts | 51 +++++++------------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/apps/core/src/bootstrap.ts b/apps/core/src/bootstrap.ts index 83dedaa5..fae816b2 100644 --- a/apps/core/src/bootstrap.ts +++ b/apps/core/src/bootstrap.ts @@ -99,6 +99,9 @@ export async function bootstrap() { logger.success( `[${prefix + pid}] Admin Local Dashboard: ${url}/proxy/qaqdmin`, ) + logger.info( + `[${prefix + pid}] If you want to debug local dev dashboard on production environment with https domain, you can go to: https:///proxy/qaqdmin/dev-proxy`, + ) logger.info(`Server is up. ${chalk.yellow(`+${performance.now() | 0}ms`)}`) }) diff --git a/apps/core/src/modules/pageproxy/pageproxy.controller.ts b/apps/core/src/modules/pageproxy/pageproxy.controller.ts index cc2f140f..999d09c2 100644 --- a/apps/core/src/modules/pageproxy/pageproxy.controller.ts +++ b/apps/core/src/modules/pageproxy/pageproxy.controller.ts @@ -21,6 +21,7 @@ import { Cookies } from '~/common/decorators/cookie.decorator' import { HTTPDecorators } from '~/common/decorators/http.decorator' import { RedisKeys } from '~/constants/cache.constant' import { LOCAL_ADMIN_ASSET_PATH } from '~/constants/path.constant' +import { AssetService } from '~/processors/helper/helper.asset.service' import { CacheService } from '~/processors/redis/cache.service' import { getRedisKey } from '~/utils/redis.util' @@ -36,6 +37,7 @@ export class PageProxyController { private readonly cacheService: CacheService, private readonly service: PageProxyService, private readonly updateService: UpdateService, + private readonly assetService: AssetService, ) {} @Get('/qaqdmin') @@ -191,39 +193,12 @@ export class PageProxyController { const isAssetPathIsExist = existsSync(entryPath) if (!isAssetPathIsExist) { this.fetchLogs = [] - reply.code(404).type('text/html') - .send(` -

Local Admin Assets is not found. Downloading start...

-

If finished download but page not reload or logs are not output for a period of time, please reload page manually.

-

-        `)
+
+      const html = await this.assetService.getAsset(
+        '/render/init-dashboard.html',
+        { encoding: 'utf-8' },
+      )
+      reply.type('text/html').send(html)
 
       this.fetchObserver$ = this.updateService.downloadAdminAsset(
         await this.updateService.getLatestAdminVersion().catch((err) => {
@@ -266,6 +241,16 @@ export class PageProxyController {
     }
   }
 
+  @Get('/proxy/qaqdmin/dev-proxy')
+  @HTTPDecorators.Bypass
+  async proxyLocalDev(@Res() reply: FastifyReply) {
+    const html = await this.assetService.getAsset('/render/local-dev.html', {
+      encoding: 'utf-8',
+    })
+
+    reply.type('text/html').send(html)
+  }
+
   @Get('/proxy/*')
   @HTTPDecorators.Bypass
   async proxyAssetRoute(