webpack: Wait for bundle before serving

This commit is contained in:
Cohee
2024-10-17 11:04:34 +00:00
parent b6f9c6480b
commit e919034132

View File

@@ -37,7 +37,7 @@ util.inspect.defaultOptions.maxStringLength = null;
util.inspect.defaultOptions.depth = 4; util.inspect.defaultOptions.depth = 4;
// local library imports // local library imports
import{ loadPlugins } from './src/plugin-loader.js'; import { loadPlugins } from './src/plugin-loader.js';
import { import {
initUserStorage, initUserStorage,
getCsrfSecret, getCsrfSecret,
@@ -440,7 +440,8 @@ app.get('/login', async (request, response) => {
}); });
// Host frontend assets // Host frontend assets
app.use(getWebpackServeMiddleware()); const webpackMiddleware = getWebpackServeMiddleware();
app.use(webpackMiddleware);
app.use(express.static(process.cwd() + '/public', {})); app.use(express.static(process.cwd() + '/public', {}));
// Public API // Public API
@@ -626,6 +627,10 @@ const tavernUrl = new URL(
(':' + server_port), (':' + server_port),
); );
function prepareFrontendBundle() {
return new Promise((resolve) => webpackMiddleware.waitUntilValid(resolve));
}
/** /**
* Tasks that need to be run before the server starts listening. * Tasks that need to be run before the server starts listening.
*/ */
@@ -675,6 +680,9 @@ const preSetupTasks = async function () {
// Add request proxy. // Add request proxy.
initRequestProxy({ enabled: proxyEnabled, url: proxyUrl, bypass: proxyBypass }); initRequestProxy({ enabled: proxyEnabled, url: proxyUrl, bypass: proxyBypass });
// Wait for frontend libs to compile
await prepareFrontendBundle();
}; };
/** /**