mirror of https://github.com/tycrek/ass
parent
b7f79a49fd
commit
7f04d365b6
@ -0,0 +1,30 @@
|
||||
import { path } from '@tycrek/joint';
|
||||
import { Router } from 'express';
|
||||
import { UserConfig } from '../UserConfig';
|
||||
import { App } from '../app';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
import { path } from '@tycrek/joint';
|
||||
import { Router, json as BodyParserJson } from 'express';
|
||||
import { log } from '../log';
|
||||
import { UserConfig } from '../UserConfig';
|
||||
import { App } from '../app';
|
||||
|
||||
const router = Router({ caseSensitive: true });
|
||||
|
||||
// Static routes
|
||||
router.get('/', (req, res) => !UserConfig.ready ? res.redirect('/') : res.render('admin', { version: App.pkgVersion }));
|
||||
router.get('/ui.js', (req, res) => !UserConfig.ready ? res.send('') : res.type('text/javascript').sendFile(path.join('dist-frontend/admin.mjs')));
|
||||
|
||||
router.post('/', BodyParserJson(), async (req, res) => {
|
||||
});
|
||||
|
||||
export { router };
|
@ -1,16 +0,0 @@
|
||||
import { path } from '@tycrek/joint';
|
||||
import { Router, json as BodyParserJson } from 'express';
|
||||
import { log } from '../log';
|
||||
import { UserConfig } from '../UserConfig';
|
||||
import { App } from '../app';
|
||||
|
||||
const router = Router({ caseSensitive: true });
|
||||
|
||||
// Static routes
|
||||
router.get('/', (req, res) => !UserConfig.ready ? res.redirect('/') : res.render('login', { version: App.pkgVersion }));
|
||||
router.get('/ui.js', (req, res) => !UserConfig.ready ? res.send('') : res.type('text/javascript').sendFile(path.join('dist-frontend/login.mjs')));
|
||||
|
||||
router.post('/', BodyParserJson(), async (req, res) => {
|
||||
});
|
||||
|
||||
export { router };
|
@ -1,16 +0,0 @@
|
||||
import { path } from '@tycrek/joint';
|
||||
import { Router, json as BodyParserJson } from 'express';
|
||||
import { log } from '../log';
|
||||
import { UserConfig } from '../UserConfig';
|
||||
import { App } from '../app';
|
||||
|
||||
const router = Router({ caseSensitive: true });
|
||||
|
||||
// Static routes
|
||||
router.get('/', (req, res) => !UserConfig.ready ? res.redirect('/') : res.render('user', { version: App.pkgVersion }));
|
||||
router.get('/ui.js', (req, res) => !UserConfig.ready ? res.send('') : res.type('text/javascript').sendFile(path.join('dist-frontend/user.mjs')));
|
||||
|
||||
router.post('/', BodyParserJson(), async (req, res) => {
|
||||
});
|
||||
|
||||
export { router };
|
Loading…
Reference in new issue