20 lines
524 B
JavaScript

import Koa from 'koa';
import * as config from './config.mjs';
import cors from '@koa/cors';
import jwt from 'koa-jwt';
import bodyParser from 'koa-bodyparser';
import routes from './routes.mjs';
import { errorAsResponse } from './middlewares/index.mjs';
const app = new Koa();
app.use(errorAsResponse);
app.use(cors());
app.use(bodyParser());
app.use(jwt({ secret: config.secret, passthrough: true }));
routes.forEach(router => {
app.use(router.routes());
app.use(router.allowedMethods());
});
app.listen(config.port);