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') })