f0ckv2/src/inc/routes/theme.mjs
2021-12-28 04:07:10 +01:00

17 lines
461 B
JavaScript

import cfg from "../config.mjs";
export default (router, tpl) => {
router.get(/^\/theme\//, async (req, res) => {
let theme = req.url.split[1] ?? cfg.websrv.themes[0];
if(!cfg.websrv.themes.includes(theme))
theme = cfg.websrv.themes[0];
return res.writeHead(301, {
"Cache-Control": "no-cache, public",
"Set-Cookie": `theme=${theme}; Path=/`,
"Location": req.headers.referer ?? "/"
}).end();
});
return router;
};