-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (26 loc) · 853 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
// server.js
'use strict'
const express = require('express');
const path = require('path') ;
const bodyParser = require('body-parser');
const app = express();
const helmet = require('helmet');
const logger = require('morgan');
const port = process.env.PORT || 8080;
const uri = 'http: //localhost: ' + port;
// const api = require('./routes/index');
app.use(helmet());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(__dirname));
app.use((req, res) => res.sendFile(`${__dirname}/index.html`));
if(app.get('env') == 'development'){
app.use((err, request, response, next) => {
console.log(err)
response.status(500).send('Error!')
});
}
app.listen(port, function(){
console.log('sever on ' + uri);
}) ;