webpack: Wait for bundle before serving
| @@ -440,7 +440,8 @@ app.get('/login', async (request, response) => { | ||
| 440 | 440 | }); |
| 441 | 441 | |
| 442 | 442 | // Host frontend assets |
| 443 | -app.use(getWebpackServeMiddleware()); | |
| 443 | +const webpackMiddleware = getWebpackServeMiddleware(); | |
| 444 | +app.use(webpackMiddleware); | |
| 444 | 445 | app.use(express.static(process.cwd() + '/public', {})); |
| 445 | 446 | |
| 446 | 447 | // Public API |
| @@ -626,6 +627,10 @@ const tavernUrl = new URL( | ||
| 626 | 627 | (':' + server_port), |
| 627 | 628 | ); |
| 628 | 629 | |
| 630 | +function prepareFrontendBundle() { | |
| 631 | + return new Promise((resolve) => webpackMiddleware.waitUntilValid(resolve)); | |
| 632 | +} | |
| 633 | + | |
| 629 | 634 | /** |
| 630 | 635 | * Tasks that need to be run before the server starts listening. |
| 631 | 636 | */ |
| @@ -675,6 +680,9 @@ const preSetupTasks = async function () { | ||
| 675 | 680 | |
| 676 | 681 | // Add request proxy. |
| 677 | 682 | initRequestProxy({ enabled: proxyEnabled, url: proxyUrl, bypass: proxyBypass }); |
| 683 | + | |
| 684 | + // Wait for frontend libs to compile | |
| 685 | + await prepareFrontendBundle(); | |
| 678 | 686 | }; |
| 679 | 687 | |
| 680 | 688 | /** |