unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import express, { Request, Response } from "express";
2import cors from "cors";
3import { logger } from "./utils/logger.js";
4import { cacheRoutes } from "./routes/remoteCache.js";
5import checkIpBlocked from "./utils/checkIpBlocked.js";
6import fs from "fs";
7import { completeEnvironment } from "./utils/backendOptions.js";
8
9fs.rmSync("cache", { recursive: true, force: true });
10fs.mkdirSync("cache");
11
12const PORT = completeEnvironment.cachePort;
13
14const app = express();
15function errorHandler(err: Error, req: Request, res: Response, next: Function) {
16 console.error(err.stack);
17 return res.status(500).json({ error: "Internal Server Error" });
18}
19
20app.use(checkIpBlocked);
21app.use(cors());
22app.set("trust proxy", 1);
23cacheRoutes(app);
24
25app.use(errorHandler);
26
27app.listen(PORT, completeEnvironment.listenIp, () => {
28 logger.info("started cacher");
29});
30
31