-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (35 loc) · 1.18 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
34
35
36
37
38
39
40
41
42
43
44
/**
* Module dependencies.
*/
const express = require('express');
const body = require('body-parser');
const path = require('path');
const logger = require('morgan');
const errorhandler = require('errorhandler');
const routes = require('./routes');
const ipaddress = require('./middleware/ippublic_middleware');
/**
* Main app.
*/
const app = express();
app.use(body.json());
app.use(body.urlencoded({extended: true}));
app.use(logger('dev'));
/* add header */
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
next();
});
app.use(ipaddress);
/* Static resources */
app.use('/public', express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.get('/', (req, res) => {
res.sendFile(__dirname + "/public/views/layout/chart.html");
});
/* Middleware catch error */
app.use(errorhandler());
module.exports = app;