-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path_express.js
30 lines (30 loc) · 974 Bytes
/
_express.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
const express = require('express')
const bodyParser = require('body-parser')
module.exports = {
init: function(options) {
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(express.static('.'))
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
if(options) {
this.view = options.view;
for(let method in options.routes) {
let handlers = options.routes[method];
for(let route in handlers) {
console.log(method);
app[method](route, handlers[route]);
console.log(route);
}
}
}
app.listen(process.env.PORT || 3000, function () { console.log('Listening!') })
},
respond: function(options) {
options.res.send(this.view[options.response.view])
}
}