1 import express from "express";
2 import path from "path";
3 import process from "process";
4 import CatchAllHandler from "./handlers/catch-all-handler";
5 import RobotsHandler from "./handlers/robots-handler";
6 import ServiceWorkerHandler from "./handlers/service-worker-handler";
7 import ThemeHandler from "./handlers/theme-handler";
8 import ThemesListHandler from "./handlers/themes-list-handler";
9 import setDefaultCsp from "./middleware/set-default-csp";
11 const server = express();
13 const [hostname, port] = process.env["LEMMY_UI_HOST"]
14 ? process.env["LEMMY_UI_HOST"].split(":")
15 : ["0.0.0.0", "1234"];
17 server.use(express.json());
18 server.use(express.urlencoded({ extended: false }));
19 server.use("/static", express.static(path.resolve("./dist")));
21 if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
22 server.use(setDefaultCsp);
25 server.get("/robots.txt", RobotsHandler);
26 server.get("/service-worker.js", ServiceWorkerHandler);
27 server.get("/css/themes/:name", ThemeHandler);
28 server.get("/css/themelist", ThemesListHandler);
29 server.get("/*", CatchAllHandler);
31 server.listen(Number(port), hostname, () => {
32 console.log(`http://${hostname}:${port}`);
35 process.on("SIGINT", () => {
36 console.info("Interrupted");