import Koa from 'koa';
import bodyParser from "koa-bodyparser";
import router from "./swagger/index.js";
import cors from "koa2-cors";

import sequelize from "./DB/index.js";

const app = new Koa();

app.use(cors());
app.use(async (ctx, next)=> {
    ctx.set('Access-Control-Allow-Origin', '*');
    ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
    ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
    await next();
});
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());



sequelize.authenticate().then(() => {
    console.log('数据库已连接');
    app.listen(9090);
}).catch(err => {
    console.error('Unable to connect to the database:', err);
});
