-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathapi.app.js
executable file
·42 lines (34 loc) · 1.02 KB
/
api.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
'use strict';
var cors = require('cors');
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var winston = require('winston');
var routes = require('./routes/routes');
var app = express();
global.logger = winston;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors());
app.use(
function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers',
'Accept,Content-Type,Authorization,Cookie');
res.header('Access-Control-Allow-Credentials', 'true');
next();
}
);
logger.remove(winston.transports.Console);
logger.add(winston.transports.Console,
{level: process.env.LOG_LEVEL || 'debug'});
routes(app);
var PORT = process.env.API_PORT;
// listen
app.listen(PORT,
function () {
logger.info('radar-api is running on port:', PORT);
}
);