-
Notifications
You must be signed in to change notification settings - Fork 159
/
server.js
28 lines (27 loc) · 899 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
const express = require('express')
const bodyParser = require('body-parser')
const { join } = require('path')
const app = express()
const yargs = require('yargs')
const argv = yargs.option('port', {
alias: 'p',
description: 'Set the port to run this server on',
type: 'number',
}).help().alias('help', 'h').argv
if(!argv.port) {
console.log('Error, you need to pass the port you want to run this application on with npm start -- -p 8001')
process.exit(0)
}
const port = argv.port
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
app.use('*', (req, res, next) => {
// Logger
let time = new Date()
console.log(`${req.method} to ${req.originalUrl} at ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`)
next()
})
app.use(express.static('dist'))
app.listen(port, '0.0.0.0', (req, res) => {
console.log(`Listening on localhost:${port}`)
})