-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (29 loc) · 933 Bytes
/
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
var express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
api = require('./routes/api');
var app = express();
// view engine
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
//
app.use(express.static(path.join(__dirname, 'dist')));
// body parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// cors
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH,DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
});
// api
app.use('/api/v1/', api);
// render index page
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(3000, function () {
console.log('Server started on port 3000...');
});