36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
async function initializeWebServer(options) {
|
|
const common = options && options.common;
|
|
const pool = options && options.pool;
|
|
const mediaDir = String(options && options.mediaDir || '').trim();
|
|
const backgroundTaskQueue = options && options.backgroundTaskQueue;
|
|
const webBootstrap = options && options.webBootstrap;
|
|
const loadCurrentUser = options && options.loadCurrentUser;
|
|
const initializeBackgroundTasks = options && options.initializeBackgroundTasks;
|
|
const captureSlideThumbnail = options && options.captureSlideThumbnail;
|
|
const dataSourceStartupRefreshStaggerMs = Math.max(100, Number(options && options.dataSourceStartupRefreshStaggerMs || 250));
|
|
const server = options && options.server;
|
|
|
|
if (!common || !pool || !mediaDir || !backgroundTaskQueue || !webBootstrap || typeof loadCurrentUser !== 'function' || typeof initializeBackgroundTasks !== 'function' || typeof captureSlideThumbnail !== 'function' || !server) {
|
|
throw new Error('initializeWebServer requires the web startup dependencies.');
|
|
}
|
|
|
|
await common.ensureSchema(pool, { mediaDir: mediaDir });
|
|
await common.bootstrapDatabase(pool);
|
|
await backgroundTaskQueue.initialize();
|
|
|
|
await initializeBackgroundTasks({
|
|
pool: pool,
|
|
common: common,
|
|
backgroundTaskQueue: backgroundTaskQueue,
|
|
notifyPlayerScreens: options && options.notifyPlayerScreens ? options.notifyPlayerScreens : null,
|
|
uploadSyncService: webBootstrap.uploadSyncService,
|
|
captureSlideThumbnail: captureSlideThumbnail,
|
|
mediaDir: mediaDir,
|
|
webBaseUrl: options && options.webBaseUrl ? options.webBaseUrl : null,
|
|
dataSourceStartupRefreshStaggerMs: dataSourceStartupRefreshStaggerMs
|
|
});
|
|
|
|
webBootstrap.installDashboardWebsocket(server, loadCurrentUser);
|
|
}
|
|
|
|
module.exports = { initializeWebServer }; |