Files
bible-api/api-gateway/src/index.ts
2026-01-08 19:10:51 +01:00

62 lines
1.6 KiB
TypeScript

import { BibleProvider } from "./providers/bible.provider.js";
import express from 'express';
import defaultRouter from "./routes/default.routes.js";
import config from "./config/config.js";
import helmet from "helmet";
import { exit } from "process";
import { DownloaderProvider } from "./providers/downloader.provider.js";
//BibleProvider.load_biliothek();
//console.log(`Loaded ${BibleProvider.biliothek.length} translations in biliothek`);
//const downloader = new DownloaderProvider.Downloader('SLT');
//downloader.start();
const app = express();
app.use(express.json());
app.use(helmet())
app.disable('x-powered-by')
app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
// log accessed url
// calculate processing time
const start = Date.now();
next();
const duration = Date.now() - start;
const access_log = {
date: new Date().toISOString(),
method: req.method,
url: req.url,
ip: req.ip,
agent: req.headers['user-agent'] || '',
status: res.statusCode,
duration: duration
}
console.log(access_log);
});
app.use('/', defaultRouter);
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
console.error(err.stack);
res.status(500).json({
requested_at: new Date().toISOString(),
rescource: "error",
data: {
message: 'Internal Server Error'
},
success: false
});
});
app.listen(config.port, () => {
console.log(`Server running on port ${config.port}`);
});