35 lines
881 B
JavaScript
35 lines
881 B
JavaScript
const express = require('express')
|
|
const path = require('path')
|
|
const app = express()
|
|
const morgan = require('morgan')
|
|
const proxy = require('http-proxy-middleware')
|
|
const port = process.env.PORT || 3001
|
|
|
|
app.use(morgan('tiny'))
|
|
|
|
app.use(proxy('/api/', { target: 'http://localhost:1337/',
|
|
changeOrigin: true }))
|
|
|
|
// body parsing middleware
|
|
app.use(express.json())
|
|
app.use(express.urlencoded({ extended: true }))
|
|
app.use(require('body-parser').text())
|
|
|
|
app.use(express.static(path.join(__dirname, 'dist')))
|
|
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.resolve(__dirname, 'dist', '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()
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Doin' haxor stuff on port ${port}`)
|
|
})
|