1
0
forked from notnull/chatz
chatz/server/index.js
notnull 477b5cd51a added socket.io
- need to add setupProxy to src to proxy requests from dev server to 
backend 
-
2019-07-14 00:25:02 -04:00

41 lines
962 B
JavaScript
Executable File

const express = require('express')
const path = require('path')
const app = express()
const morgan = require('morgan')
const ascii = require('./ascii')
const socketio = require('socket.io')
const port = process.env.PORT || 1337
app.use(morgan('tiny'))
// body parsing middleware
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(require('body-parser').text())
app.use('/api', require('./api'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'public', 'index.html'))
})
// error handling endware
app.use((err, req, res, next) => {
console.error(err)
console.error(err.stack)
res.status(err.status || 500).send(err.message || 'Internal server error.')
next()
})
const startListening = () => {
const server = app.listen(port, () => {
console.log(ascii)
console.log(`Doin' haxor stuff on port ${port}`)
})
const io = socketio(server)
require('./socket')(io)
}
startListening()