2023-06-22 23:33:02 +00:00
|
|
|
import setDefaultOptions from "date-fns/setDefaultOptions";
|
2021-02-22 02:39:04 +00:00
|
|
|
import express from "express";
|
|
|
|
import path from "path";
|
2021-07-17 20:42:55 +00:00
|
|
|
import process from "process";
|
2023-06-22 23:33:02 +00:00
|
|
|
import { I18NextService } from "../shared/services";
|
2023-06-16 14:34:36 +00:00
|
|
|
import CatchAllHandler from "./handlers/catch-all-handler";
|
2023-06-21 11:55:27 +00:00
|
|
|
import ManifestHandler from "./handlers/manifest-handler";
|
2023-06-16 14:34:36 +00:00
|
|
|
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";
|
2023-05-14 20:25:03 +00:00
|
|
|
|
2020-08-23 04:04:58 +00:00
|
|
|
const server = express();
|
2023-06-16 14:34:36 +00:00
|
|
|
|
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"];
|
2022-05-25 03:33:11 +00:00
|
|
|
|
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
|
|
|
|
2023-06-16 14:34:36 +00:00
|
|
|
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
|
|
|
|
server.use(setDefaultCsp);
|
2022-03-02 15:35:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 14:34:36 +00:00
|
|
|
server.get("/robots.txt", RobotsHandler);
|
|
|
|
server.get("/service-worker.js", ServiceWorkerHandler);
|
2023-06-22 01:04:28 +00:00
|
|
|
server.get("/manifest.webmanifest", ManifestHandler);
|
2023-06-16 14:34:36 +00:00
|
|
|
server.get("/css/themes/:name", ThemeHandler);
|
|
|
|
server.get("/css/themelist", ThemesListHandler);
|
|
|
|
server.get("/*", CatchAllHandler);
|
2020-11-12 21:56:46 +00:00
|
|
|
|
2021-03-29 15:35:32 +00:00
|
|
|
server.listen(Number(port), hostname, () => {
|
|
|
|
console.log(`http://${hostname}:${port}`);
|
2020-08-23 04:04:58 +00:00
|
|
|
});
|
|
|
|
|
2023-06-22 23:33:02 +00:00
|
|
|
process.on("SIGINT", async () => {
|
|
|
|
const lang = I18NextService.i18n.language;
|
|
|
|
const locale = (
|
|
|
|
await import(
|
|
|
|
/* webpackExclude: /\.js\.flow$/ */
|
|
|
|
`date-fns/locale/${lang}`
|
|
|
|
)
|
|
|
|
).default;
|
|
|
|
setDefaultOptions({
|
|
|
|
locale,
|
|
|
|
});
|
2021-02-22 02:39:04 +00:00
|
|
|
console.info("Interrupted");
|
2020-09-10 16:39:01 +00:00
|
|
|
process.exit(0);
|
|
|
|
});
|