mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-13 06:08:58 +02:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { config as dotenv } from "dotenv";
|
|
dotenv();
|
|
|
|
import * as express from "express";
|
|
import * as compression from "compression";
|
|
|
|
import config from "../config";
|
|
import router from "./route";
|
|
import { handleError } from "../server/routes/route-utils";
|
|
import AnonymousError from "../core/AnonymousError";
|
|
import { createLogger } from "../core/logger";
|
|
|
|
const logger = createLogger("streamer");
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.use(
|
|
compression({
|
|
filter: (req, res) => {
|
|
// The streamer serves file blobs that are often binary (images,
|
|
// archives) and can be very large. Compressing them holds zlib
|
|
// buffers per response that pile up under concurrent load.
|
|
if (req.path === "/api" && req.method === "POST") return false;
|
|
return compression.filter(req, res);
|
|
},
|
|
})
|
|
);
|
|
|
|
app.use("/api", router);
|
|
|
|
app.get("/healthcheck", async (_, res) => {
|
|
res.json({ status: "ok" });
|
|
});
|
|
|
|
app.all("/{*path}", (req, res) => {
|
|
handleError(
|
|
new AnonymousError("file_not_found", {
|
|
httpStatus: 404,
|
|
url: req.originalUrl,
|
|
}),
|
|
res,
|
|
req
|
|
);
|
|
});
|
|
app.listen(config.PORT, (error?: Error) => {
|
|
if (error) throw error;
|
|
logger.info("streamer started", { port: config.PORT });
|
|
});
|