-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathserver.js
43 lines (33 loc) · 1.04 KB
/
server.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
34
35
36
37
38
39
40
41
42
43
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
require('./config')(app);
require('./models')(app);
var config = app.get('config');
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
if ('OPTIONS' === req.method) {
res.status(200).end();
} else {
next();
}
});
app.use(express.static(__dirname + '/adminpanel'));
app.get('/add-news', function (req, res) {
res.sendFile(__dirname + '/adminpanel/add-news.html');
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
var router = express.Router();
app.set('router', router);
app.use(router);
var http = require('http');
http.createServer(app)
.listen(config.PORT, function () {
console.log('app start on port ' + config.PORT);
});