0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -05:00
safetwitch/server/index.ts
2023-03-07 01:19:05 -05:00

36 lines
No EOL
742 B
TypeScript

import express, { Express, NextFunction, Request, Response } from 'express';
import dotenv from 'dotenv'
import history from 'connect-history-api-fallback'
import routes from './routes'
dotenv.config()
const app: Express = express();
const port = process.env.PORT
app.use(routes)
app.use(history())
app.use(express.static('../frontend/dist'))
// 404 handler
app.use((req, res) => {
if (!res.headersSent) {
res.status(404).send('404')
}
});
// handle errors
app.use(errorHandler)
function errorHandler(err: Error, req: Request, res: Response, next: NextFunction) {
if (res.headersSent) {
return next(err)
}
res.status(500)
res.send('error')
console.log(err)
}
app.listen(port, () => {
console.log('Server up')
})