-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (26 loc) · 847 Bytes
/
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
const Koa = require('koa');
const app = new Koa();
const bodyParser = require('koa-bodyparser');
// const photo = require('./static/photo');
const data = require('./data');
app.use(bodyParser());
app.use((ctx, next) => {
console.log('header')
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Methods', 'PUT, GET, POST, OPTIONS, PATCH, DELETE');
ctx.set('Access-Control-Allow-Headers', 'x-requested-with, accept, origin, content-type');
ctx.set('Access-Control-Max-Age', 30)
next();
});
const main = async function (ctx, next) {
console.log('come on');
console.log('app.env' + app.env)
ctx.response.type = 'json';
const obj = JSON.stringify(data);
ctx.response.body = obj;
await next();
};
app.use(main);
app.listen(3600, function () {
console.log('Exapmle app listening on port 3600!');
});