webpack: Wait for bundle before serving

e919034132b0493c71c0dc6a804ad756e1d4fad0

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -2Ignore whitespace
server.js+10 -2
@@ -37,7 +37,7 @@ util.inspect.defaultOptions.maxStringLength = null;
37util.inspect.defaultOptions.depth = 4;37util.inspect.defaultOptions.depth = 4;
3838
39// local library imports39// local library imports
40import{ loadPlugins } from './src/plugin-loader.js';40import { loadPlugins } from './src/plugin-loader.js';
41import {41import {
42 initUserStorage,42 initUserStorage,
43 getCsrfSecret,43 getCsrfSecret,
@@ -440,7 +440,8 @@ app.get('/login', async (request, response) => {
440});440});
441441
442// Host frontend assets442// Host frontend assets
443app.use(getWebpackServeMiddleware());443const webpackMiddleware = getWebpackServeMiddleware();
444app.use(webpackMiddleware);
444app.use(express.static(process.cwd() + '/public', {}));445app.use(express.static(process.cwd() + '/public', {}));
445446
446// Public API447// Public API
@@ -626,6 +627,10 @@ const tavernUrl = new URL(
626 (':' + server_port),627 (':' + server_port),
627);628);
628629
630function prepareFrontendBundle() {
631 return new Promise((resolve) => webpackMiddleware.waitUntilValid(resolve));
632}
633
629/**634/**
630 * Tasks that need to be run before the server starts listening.635 * Tasks that need to be run before the server starts listening.
631 */636 */
@@ -675,6 +680,9 @@ const preSetupTasks = async function () {
675680
676 // Add request proxy.681 // Add request proxy.
677 initRequestProxy({ enabled: proxyEnabled, url: proxyUrl, bypass: proxyBypass });682 initRequestProxy({ enabled: proxyEnabled, url: proxyUrl, bypass: proxyBypass });
683
684 // Wait for frontend libs to compile
685 await prepareFrontendBundle();
678};686};
679687
680/**688/**