-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
35 lines (30 loc) · 940 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
34
35
'use strict'
const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const chalk = require('chalk')
const app = express()
const PORT = 8080
app.use(morgan('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// static middleware so your browser can request things like your 'bundle.js'
app.use(express.static(path.join(__dirname, 'public')))
// Send index.html for any other requests
app.use('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'))
})
// error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(err.status || 500).send(err.message || 'Internal server error')
})
app.listen(PORT, err => {
if (err) {
console.error(err)
return
}
console.log(chalk.magenta(`listening at http://localhost:${PORT}`))
})
module.exports = app