import express, { RequestHandler } from "express"; import { StaticRouter } from "inferno-router"; import { renderToString } from "inferno-server"; // import { matchPath } from "inferno-router"; import path from "path"; import { App } from "../shared/components/app"; // import { routes } from "../shared/routes"; import process from "process"; import { Helmet } from "inferno-helmet"; import { getLanguageFromCookie, i18n } from "../shared/i18next"; const server = express(); const port = 1234; server.use(express.json() as RequestHandler); server.use(express.urlencoded({ extended: false }) as RequestHandler); server.use("/static", express.static(path.resolve("./dist"))); server.use("/docs", express.static(path.resolve("./dist/assets/docs"))); server.use("/api", express.static(path.resolve("./dist/assets/api"))); server.get("/*", async (req, res) => { // const activeRoute = routes.find(route => matchPath(req.path, route)) || {}; const context = {} as any; // Setting the language for non-js browsers const cookieLang = getLanguageFromCookie(req.headers.cookie); var language: string; if (req.query["lang"] != null) { language = req.query["lang"].toString(); res.cookie("lang", language, { expires: new Date(Date.now() + 60 * 60 * 24 * 7), }); } else if (cookieLang != null) { language = cookieLang; } else { language = req.headers["accept-language"] ? req.headers["accept-language"].split(",")[0] : "en"; } i18n.changeLanguage(language); const wrapper = ( ); if (context.url) { return res.redirect(context.url); } const root = renderToString(wrapper); const helmet = Helmet.renderStatic(); res.send(` ${helmet.title.toString()} ${helmet.meta.toString()} ${helmet.link.toString()}
${root}
`); }); server.listen(port, () => { console.log(`http://localhost:${port}`); }); process.on("SIGINT", () => { console.info("Interrupted"); process.exit(0); });