1
This commit is contained in:
31
server/app.js
Normal file
31
server/app.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import dotenv from 'dotenv';
|
||||
import Koa from 'koa';
|
||||
import body_parser from 'koa-bodyparser';
|
||||
|
||||
import { sequelize } from './models/index.js';
|
||||
import { crawl_router } from './routes/crawl.js';
|
||||
import { schedule_task_router } from './routes/schedule_task.js';
|
||||
import { reload_all_schedules } from './services/schedule_loader.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = new Koa();
|
||||
app.use(body_parser({ jsonLimit: '10mb' }));
|
||||
|
||||
app.use(crawl_router.routes()).use(crawl_router.allowedMethods());
|
||||
app.use(schedule_task_router.routes()).use(schedule_task_router.allowedMethods());
|
||||
|
||||
app.use(async (ctx) => {
|
||||
ctx.status = 404;
|
||||
ctx.body = { ok: false, error: 'not_found' };
|
||||
});
|
||||
|
||||
const port = Number(process.env.SERVER_PORT || 38080);
|
||||
|
||||
await sequelize.authenticate();
|
||||
await sequelize.sync();
|
||||
await reload_all_schedules();
|
||||
|
||||
app.listen(port);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`server listening on ${port}`);
|
||||
Reference in New Issue
Block a user