-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (36 loc) · 1.11 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
44
45
const express = require('express');
const app = express();
const cors = require('cors');
app.use(express.json());
app.use(express.urlencoded({exteneded:true}));
app.use(cors());
const port = process.env.PORT || 8080;
// require('./database');
//logging details
const logger = require('morgan');
const fs = require('fs');
const path = require('path');
logger.token('host', (req, res)=>{
return req.hostname;
});
let accessLogStream = fs.createWriteStream(path.join(__dirname, 'covid-19.log'),{flags: 'a'});
app.use(logger('[:date[web]] :method :host :url :status :res[content-length] - :response-time ms',{ stream: accessLogStream}));
app.use(logger('dev'));
//api call
const users = require("./api/users");
app.use('/',users);
app.get('/logs',(req, res)=>{
fs.readFile('hackx.log', function(err, data) {
res.send(data);
});
});
//public files
app.use(express.static(path.join(__dirname,'/public')));
//welcome page
app.get(['/','/home','/index.html'],(req, res)=>{
res.sendFile(path.join(__dirname,'/public/index.html'));
})
//listen
app.listen(port, ( ) => {
console.log(`The server is running on ${port}`);
})