Feature: use nuxt bridge to bundle client

This commit is contained in:
Aram Becker 2023-05-04 23:52:36 +02:00
parent 98c117f0b8
commit 228b5203a8
23 changed files with 8484 additions and 19783 deletions

View file

@ -139,7 +139,7 @@ class Server {
Logger.info('=== Starting Server ===')
await this.init()
if (process.env.NODE_ENV !== 'development') {
this.clientRouter.start()
await this.clientRouter.start()
}
const app = express()

View file

@ -1,4 +1,5 @@
const express = require('express')
const mime = require('mime-types')
const Path = require('path')
const Logger = require('../Logger')
@ -14,18 +15,15 @@ class ClientRouter {
async init () {
const clientDir = Path.join(this.appRoot, '/client')
const { loadNuxt } = require(Path.resolve(clientDir, 'node_modules/nuxt'))
this.client = await loadNuxt({ rootDir: clientDir, for: 'start' })
const { handler } = await import(Path.join(clientDir, '.output/server/index.mjs'))
this.client = handler
}
async start () {
Logger.info('[Client] Starting')
await this.init()
this.router.use(this.client.render)
this.client.hook('error', (err) => Logger.error('[Client]', err))
this.client.ready().then(() => Logger.info('[Client] Ready'))
this.router.use('/', this.client)
}
async stop () {