lemmy-ui/src/server/index.tsx

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-06-23 14:10:41 +00:00
import { setupI18Next as setupDateFns } from "@utils/app";
2021-02-22 02:39:04 +00:00
import express from "express";
import path from "path";
import process from "process";
import CatchAllHandler from "./handlers/catch-all-handler";
import ManifestHandler from "./handlers/manifest-handler";
import RobotsHandler from "./handlers/robots-handler";
import ServiceWorkerHandler from "./handlers/service-worker-handler";
import ThemeHandler from "./handlers/theme-handler";
import ThemesListHandler from "./handlers/themes-list-handler";
import setDefaultCsp from "./middleware/set-default-csp";
2020-08-23 04:04:58 +00:00
const server = express();
2021-03-30 01:46:42 +00:00
const [hostname, port] = process.env["LEMMY_UI_HOST"]
? process.env["LEMMY_UI_HOST"].split(":")
2021-03-30 01:17:19 +00:00
: ["0.0.0.0", "1234"];
2020-08-23 04:04:58 +00:00
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
2021-02-22 02:39:04 +00:00
server.use("/static", express.static(path.resolve("./dist")));
2020-08-23 04:04:58 +00:00
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
server.use(setDefaultCsp);
}
server.get("/robots.txt", RobotsHandler);
server.get("/service-worker.js", ServiceWorkerHandler);
server.get("/manifest.webmanifest", ManifestHandler);
server.get("/css/themes/:name", ThemeHandler);
server.get("/css/themelist", ThemesListHandler);
server.get("/*", CatchAllHandler);
server.listen(Number(port), hostname, () => {
2023-06-23 14:10:41 +00:00
setupDateFns();
console.log(`http://${hostname}:${port}`);
2020-08-23 04:04:58 +00:00
});
2023-06-23 14:10:41 +00:00
process.on("SIGINT", () => {
2021-02-22 02:39:04 +00:00
console.info("Interrupted");
process.exit(0);
});