55 lines
No EOL
1.2 KiB
JavaScript
55 lines
No EOL
1.2 KiB
JavaScript
import { importRouters } from "./lib.js";
|
|
|
|
const aliases = {
|
|
'/': '/walls/get/home'
|
|
};
|
|
|
|
const routers = {
|
|
'/you': './you.js'
|
|
}
|
|
|
|
function doAliases(app) {
|
|
for (let alias in aliases) {
|
|
app.all(alias, (req, res, next) => {
|
|
res.redirect(aliases[alias])
|
|
})
|
|
}
|
|
}
|
|
|
|
async function doInit(app) {
|
|
app.use((req, res, next) => {
|
|
let headerCtx = [
|
|
{ link: '/walls/get/home', icon: '/icon.svg', name: 'DervNet' },
|
|
{ link: '/walls/list', icon: '/walls.svg', name: 'Explore' },
|
|
{ link: '/you/logout', icon: '/logout.svg', name: 'Leave' } // fix icon
|
|
];
|
|
|
|
if (!res.auth || !res.auth.valid) {
|
|
headerCtx = [
|
|
{ link: '/walls/get/home', icon: '/icon.svg', name: 'DervNet' },
|
|
{ link: '/you/login', icon: '/walls.svg', name: 'Log in' }
|
|
];
|
|
}
|
|
|
|
res.ctx = {
|
|
mainPage: '404.ejs',
|
|
mainCtx: {},
|
|
headerCtx
|
|
};
|
|
next();
|
|
})
|
|
|
|
doAliases(app);
|
|
|
|
await importRouters(app,routers);
|
|
|
|
app.use('/api', (req, res, next) => {
|
|
res.send(res.ctx);
|
|
})
|
|
|
|
app.use((req, res, next) => {
|
|
res.render('root.ejs', res.ctx)
|
|
})
|
|
}
|
|
|
|
export { doInit }; |