diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2022-12-20 13:05:36 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-20 13:05:36 +0900 |
| commit | 2fe86fd86937b47969447d91bb987b7e0233afd5 (patch) | |
| tree | af191c8be7193a1e5b254f1e857b14e8023f90d2 /packages/backend/src/server/web/ClientServerService.ts | |
| parent | :art: (diff) | |
| download | sharkey-2fe86fd86937b47969447d91bb987b7e0233afd5.tar.gz sharkey-2fe86fd86937b47969447d91bb987b7e0233afd5.tar.bz2 sharkey-2fe86fd86937b47969447d91bb987b7e0233afd5.zip | |
enhance: Vite HMR while yarn dev, and more build tuning (#9361)
* enhance: Vite HMR while yarn dev, and more build tuning
* use localhost
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/server/web/ClientServerService.ts')
| -rw-r--r-- | packages/backend/src/server/web/ClientServerService.ts | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 58452ae826..c537d9a369 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -12,6 +12,7 @@ import { In, IsNull } from 'typeorm'; import fastifyStatic from '@fastify/static'; import fastifyView from '@fastify/view'; import fastifyCookie from '@fastify/cookie'; +import fastifyProxy from '@fastify/http-proxy'; import type { Config } from '@/config.js'; import { getNoteSummary } from '@/misc/get-note-summary.js'; import { DI } from '@/di-symbols.js'; @@ -39,6 +40,7 @@ const staticAssets = `${_dirname}/../../../assets/`; const clientAssets = `${_dirname}/../../../../client/assets/`; const assets = `${_dirname}/../../../../../built/_client_dist_/`; const swAssets = `${_dirname}/../../../../../built/_sw_dist_/`; +const viteOut = `${_dirname}/../../../../../built/_vite_/`; @Injectable() export class ClientServerService { @@ -151,9 +153,6 @@ export class ClientServerService { }, defaultContext: { version: this.config.version, - getClientEntry: () => process.env.NODE_ENV === 'production' ? - this.config.clientEntry : - JSON.parse(readFileSync(`${_dirname}/../../../../../built/_client_dist_/manifest.json`, 'utf-8'))['src/init.ts'], config: this.config, }, }); @@ -164,6 +163,23 @@ export class ClientServerService { done(); }); + //#region vite assets + if (this.config.clientManifestExists) { + fastify.register(fastifyStatic, { + root: viteOut, + prefix: '/vite/', + maxAge: ms('30 days'), + decorateReply: false, + }); + } else { + fastify.register(fastifyProxy, { + upstream: 'http://localhost:5173', // TODO: port configuration + prefix: '/vite', + rewritePrefix: '/vite', + }); + } + //#endregion + //#region static assets fastify.register(fastifyStatic, { |