-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
33 lines (29 loc) · 1.07 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Koa = require('koa');
const app = new Koa();
const convert = require('koa-convert');//将koa1的中间封装为koa2的中间件
const bodyParser = require('koa-bodyparser');
const logger = require('koa-logger');//在控制台输出日志
const views = require("koa-views");//配置koa的模版引擎
const cors = require("koa-cors");
app.use(convert(cors()));
app.use(convert(bodyParser()));
app.use(convert(logger()));
app.use(convert(require("koa-static")(__dirname+"/public")));//静态文件地址
app.use(views(__dirname+"/views",{ //选择ejs作为模版引擎,但是可以用html作为后缀
map:{
html:"ejs"
}
}));
require('./init')();
var index = require("./routes/index");
var course = require('./routes/course');
var order = require('./routes/order');
var user = require('./routes/user');
app.use(index.routes(),index.allowedMethods());
app.use(course.routes(), course.allowedMethods());
app.use(order.routes(), order.allowedMethods());
app.use(user.routes(), user.allowedMethods());
app.on('error', function (err, ctx) {
console.log(err);
});
module.exports = app;