40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const Fastify = require('fastify');
|
|
const cors = require('@fastify/cors');
|
|
const articleRoutes = require('./src/routes/articles');
|
|
const statusRoutes = require('./src/routes/status');
|
|
const sourcesRoutes = require('./src/routes/sources');
|
|
const eventRoutes = require('./src/routes/events');
|
|
const adminRoutes = require('./src/routes/admin');
|
|
const devRoutes = require('./src/routes/dev');
|
|
const autonomyRoutes = require('./src/routes/autonomy');
|
|
const config = require('./src/config');
|
|
const { startScheduler } = require('./src/scheduler');
|
|
|
|
const app = Fastify({ logger: true });
|
|
|
|
app.register(cors, { origin: true });
|
|
app.register(articleRoutes);
|
|
app.register(statusRoutes);
|
|
app.register(sourcesRoutes);
|
|
app.register(eventRoutes);
|
|
app.register(adminRoutes);
|
|
app.register(devRoutes);
|
|
app.register(autonomyRoutes);
|
|
|
|
app.get('/', async () => ({ ok: true }));
|
|
|
|
async function start() {
|
|
await app.listen({ port: config.server.port, host: config.server.host });
|
|
|
|
if (process.env.DURIIN_RUN_SCHEDULER !== 'false') {
|
|
startScheduler();
|
|
} else {
|
|
app.log.warn('Background ingestion and enrichment scheduler is disabled');
|
|
}
|
|
}
|
|
|
|
start().catch((error) => {
|
|
app.log.error(error);
|
|
process.exit(1);
|
|
});
|