diff --git a/src/server/index.tsx b/src/server/index.tsx index ca01fa1..d0aa51c 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -1,4 +1,4 @@ -import express, { RequestHandler } from "express"; +import express, { RequestHandler, Request, Response } from "express"; import { StaticRouter } from "inferno-router"; import { renderToString } from "inferno-server"; // import { matchPath } from "inferno-router"; @@ -18,13 +18,21 @@ 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; +function erudaInit(): string { + if (process.env["NODE_ENV"] == "development") { + return ` + + + `; + } else { + return ""; + } +} +function setLanguage(req: Request, res: Response): string { // Setting the language for non-js browsers const cookieLang = getLanguageFromCookie(req.headers.cookie); - var language: string; + let language: string; if (req.query["lang"] != null) { language = req.query["lang"].toString(); res.cookie("lang", language, { @@ -37,6 +45,14 @@ server.get("/*", async (req, res) => { ? req.headers["accept-language"].split(",")[0] : "en"; } + return language; +} + +server.get("/*", async (req, res) => { + // const activeRoute = routes.find(route => matchPath(req.path, route)) || {}; + const context = {} as any; + + const language = setLanguage(req, res); i18n.changeLanguage(language); const wrapper = ( @@ -50,14 +66,12 @@ server.get("/*", async (req, res) => { const root = renderToString(wrapper); const helmet = Helmet.renderStatic(); - // TODO make eruda only work in debug mode res.send(` - - + ${erudaInit()} ${helmet.title.toString()} ${helmet.meta.toString()}