unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at api-load-balancing 28 lines 816 B view raw
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 res.send(500).json({ error: 'Internal Server Error' }) 18} 19app.use(errorHandler) 20 21app.use(checkIpBlocked) 22app.use(cors()) 23app.set('trust proxy', 1) 24 25cacheRoutes(app) 26app.listen(PORT, completeEnvironment.listenIp, () => { 27 logger.info('started cacher') 28})