78 lines
3.5 KiB
JavaScript
78 lines
3.5 KiB
JavaScript
// Generated, do not edit. sha256:b9a3a6b8f1e1fdbee54a4d9e67411a1659c1ea24437a706bbf1a46f443c3b26d
|
|||
|
|
import { createServer as createHttpServer } from 'node:http';
|
||
|
|
import { createServer as createHttpsServer } from 'node:https';
|
||
|
|
import { spawn } from 'node:child_process';
|
||
|
|
import { createRequestListener, CLIENT } from './app.mjs';
|
||
|
|
import { loadCredentials, loadTlsOptions, resolveBinding } from './auth.mjs';
|
||
|
|
import { initDatabase, one } from './db.js';
|
||
|
|
import { getProvider } from './data/providers.js';
|
||
|
|
import { moveProviderKeys } from './keys.mjs';
|
||
|
|
import { prepareLayout } from './portfolios.mjs';
|
||
|
|
import { licenseState, appVersion, hasFeature } from './license.mjs';
|
||
|
|
import { getPref } from './data/preferences.js';
|
||
|
|
import { adoptInstallLocale } from './installation.mjs';
|
||
|
|
import { services } from './registers.mjs';
|
||
|
|
import './edition.mjs';
|
||
|
|
|
||
|
|
const PORT = Number(process.env.PORT) || 8080;
|
||
|
|
|
||
|
|
function openInBrowser(url) {
|
||
|
|
const [cmd, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]]
|
||
|
|
: process.platform === 'darwin' ? ['open', [url]]
|
||
|
|
: ['xdg-open', [url]];
|
||
|
|
try {
|
||
|
|
spawn(cmd, args, { detached: true, stdio: 'ignore' }).unref();
|
||
|
|
} catch (e) {
|
||
|
|
console.error('[assetapp] browser openen mislukt:', e.message);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let credentials, tls, binding, dbRegel, portefeuilleRegel;
|
||
|
|
try {
|
||
|
|
portefeuilleRegel = prepareLayout().regel;
|
||
|
|
credentials = await loadCredentials();
|
||
|
|
tls = await loadTlsOptions();
|
||
|
|
binding = resolveBinding({ tls: Boolean(tls), credentials, host: process.env.ASSETAPP_HOST || null });
|
||
|
|
dbRegel = initDatabase();
|
||
|
|
if (!getProvider('eulerpool_metal') && getProvider('eulerpool')) await moveProviderKeys('eulerpool_metal', 'eulerpool');
|
||
|
|
const oldLocale = one(`SELECT value FROM Preference WHERE scope = 'app' AND key = 'locale'`);
|
||
|
|
adoptInstallLocale(oldLocale ? JSON.parse(oldLocale.value) : undefined);
|
||
|
|
} catch (e) {
|
||
|
|
console.error(`[assetapp] kan niet starten: ${e.message}`);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (process.channel) {
|
||
|
|
process.on('disconnect', () => {
|
||
|
|
console.log('[assetapp] de supervisor is weg; de server stopt.');
|
||
|
|
process.exit(0);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
const server = tls
|
||
|
|
? createHttpsServer(tls, createRequestListener({ credentials, secure: true }))
|
||
|
|
: createHttpServer(createRequestListener({ credentials, secure: false }));
|
||
|
|
|
||
|
|
server.listen(PORT, binding.host, () => {
|
||
|
|
const schema = tls ? 'https' : 'http';
|
||
|
|
const url = `${schema}://localhost:${PORT}`;
|
||
|
|
console.log(`[assetapp] serveert ${CLIENT} op ${url}`);
|
||
|
|
const bron = credentials ? (process.env.ASSETAPP_PASSWORD ? 'omgeving' : 'portefeuille') : null;
|
||
|
|
console.log(`[assetapp] TLS: ${tls ? 'aan' : 'uit'} | toegangscontrole: ${credentials ? `aan (${bron})` : 'uit'}`
|
||
|
|
+ ` | luistert op: ${binding.host}`);
|
||
|
|
console.log(`[assetapp] ${portefeuilleRegel}`);
|
||
|
|
console.log(`[assetapp] ${dbRegel}`);
|
||
|
|
const lic = licenseState();
|
||
|
|
console.log(`[assetapp] licentie: ${lic.level === 'full' ? 'volledig' : 'gratis stand'}`
|
||
|
|
+ ` (${lic.why}) | versie: ${appVersion()}`);
|
||
|
|
if (binding.waarschuwing) console.warn(`[assetapp] LET OP: ${binding.waarschuwing}`);
|
||
|
|
else if (binding.host === '127.0.0.1') {
|
||
|
|
console.log('[assetapp] Alleen bereikbaar vanaf deze machine. Van een ander apparaat erbij kunnen'
|
||
|
|
+ ' vergt TLS én inloggegevens.');
|
||
|
|
}
|
||
|
|
if (process.env.ASSETAPP_OPEN === '1') {
|
||
|
|
const kiosk = services.get('kiosk');
|
||
|
|
kiosk?.forget();
|
||
|
|
if (!(kiosk && hasFeature('kiosk') && getPref('app', 'kiosk') && kiosk.start(url))) openInBrowser(url);
|
||
|
|
}
|
||
|
|
});
|