-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
40 lines (33 loc) · 1 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
/* eslint-env node */
'use strict';
const express = require('express');
const fetch = require('node-fetch');
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS;
/**
* Starts the Express server.
*
* @return {ExpressServer} instance of the Express server.
*/
function startServer() {
const app = express();
// Redirect HTTP to HTTPS,
app.use(redirectToHTTPS([/localhost:(\d{4})/], [], 301));
// Logging for each request
app.use((req, resp, next) => {
const now = new Date();
const time = `${now.toLocaleDateString()} - ${now.toLocaleTimeString()}`;
const path = `"${req.method} ${req.path}"`;
const m = `${req.ip} - ${time} - ${path}`;
// eslint-disable-next-line no-console
console.log(m);
next();
});
// Handle requests for static files
app.use(express.static('./'));
// Start the server
return app.listen('5000', () => {
// eslint-disable-next-line no-console
console.log('Local DevServer Started on port 5000...');
});
}
startServer();