webpack: Wait for bundle before serving
| @@ -440,7 +440,8 @@ app.get('/login', async (request, response) => { | |||
| 440 | }); | 440 | }); |
| 441 | 441 | ||
| 442 | // Host frontend assets | 442 | // Host frontend assets |
| 443 | app.use(getWebpackServeMiddleware()); | 443 | const webpackMiddleware = getWebpackServeMiddleware(); |
| 444 | app.use(webpackMiddleware); | ||
| 444 | app.use(express.static(process.cwd() + '/public', {})); | 445 | app.use(express.static(process.cwd() + '/public', {})); |
| 445 | 446 | ||
| 446 | // Public API | 447 | // Public API |
| @@ -626,6 +627,10 @@ const tavernUrl = new URL( | |||
| 626 | (':' + server_port), | 627 | (':' + server_port), |
| 627 | ); | 628 | ); |
| 628 | 629 | ||
| 630 | function 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 () { | |||
| 675 | 680 | ||
| 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 | }; |
| 679 | 687 | ||
| 680 | /** | 688 | /** |