You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { Router } from 'express';
|
|
|
|
import { path } from '@tycrek/joint';
|
|
|
|
|
|
|
|
import { App } from '../app';
|
|
|
|
import { UserConfig } from '../UserConfig';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a basic router for loading a page with frontend JS
|
|
|
|
*/
|
|
|
|
export const buildFrontendRouter = (page: string, onConfigReady = true) => {
|
|
|
|
|
|
|
|
// Config readiness checker
|
|
|
|
const ready = () => (onConfigReady)
|
|
|
|
? UserConfig.ready
|
|
|
|
: !UserConfig.ready;
|
|
|
|
|
|
|
|
// Set up a router
|
|
|
|
const router = Router({ caseSensitive: true });
|
|
|
|
|
|
|
|
// Render the page
|
|
|
|
router.get('/', (_req, res) => ready()
|
|
|
|
? res.render(page, { version: App.pkgVersion })
|
|
|
|
: res.redirect('/'));
|
|
|
|
|
|
|
|
// Load frontend JS
|
|
|
|
router.get('/ui.js', (_req, res) => ready()
|
|
|
|
? res.type('text/javascript').sendFile(path.join(`dist-frontend/${page}.mjs`))
|
|
|
|
: res.sendStatus(403));
|
|
|
|
|
|
|
|
return router;
|
|
|
|
};
|