import express, { RequestHandler, Request, Response } 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.use(
"/context.json",
express.static(path.resolve("./dist/assets/lemmy_federation_context.json")),
);
server.use("/feed.xml", express.static(path.resolve("./dist/feed.xml")));
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);
let 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";
}
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 = (