mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-08-04 10:16:41 +00:00
Some checks failed
Deploy Addon / build (SSH_HOST_1, SSH_KEY_1) (push) Has been cancelled
Deploy Addon / build (SSH_HOST_2, SSH_KEY_2) (push) Has been cancelled
Deploy Addon / build (SSH_HOST_3, SSH_KEY_3) (push) Has been cancelled
Deploy Addon / build (SSH_HOST_4, SSH_KEY_4) (push) Has been cancelled
Deploy Addon / build (SSH_HOST_5, SSH_KEY_5) (push) Has been cancelled
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
import express from 'express';
|
|
import swStats from 'swagger-stats';
|
|
import serverless, { redisClient } from './serverless.js';
|
|
import { manifest } from './lib/manifest.js';
|
|
import { initBestTrackers } from './lib/magnetHelper.js';
|
|
import { closeDatabase } from './lib/repository.js';
|
|
import { closeCache } from './lib/cache.js';
|
|
|
|
const app = express();
|
|
app.enable('trust proxy');
|
|
app.use(swStats.getMiddleware({
|
|
name: manifest().name,
|
|
version: manifest().version,
|
|
timelineBucketDuration: 60 * 60 * 1000,
|
|
apdexThreshold: 100,
|
|
authentication: true,
|
|
onAuthenticate: (req, username, password) => {
|
|
return username === process.env.METRICS_USER
|
|
&& password === process.env.METRICS_PASSWORD
|
|
},
|
|
}))
|
|
app.use(express.static('static', { maxAge: '1y' }));
|
|
app.use((req, res, next) => serverless(req, res, next));
|
|
const server = app.listen(process.env.PORT || 7000, () => {
|
|
initBestTrackers()
|
|
.then(() => console.log(`Started addon at: http://localhost:${process.env.PORT || 7000}`));
|
|
});
|
|
|
|
async function shutdown(signal) {
|
|
console.log(`Received ${signal}, shutting down gracefully`);
|
|
const forced = setTimeout(() => process.exit(1), 15000);
|
|
await new Promise(resolve => server.close(resolve));
|
|
await Promise.allSettled([closeDatabase(), closeCache(), redisClient.quit()]);
|
|
clearTimeout(forced);
|
|
process.exit(0);
|
|
}
|
|
|
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
process.on('SIGINT', () => shutdown('SIGINT'));
|