| | import 'dotenv/config'; |
| | import express, { Request, Response, NextFunction } from 'express'; |
| | import cors from 'cors'; |
| | import { isBoom } from '@hapi/boom'; |
| | import { fileURLToPath } from 'url'; |
| | import { dirname, join } from 'path'; |
| |
|
| | const __filename = fileURLToPath(import.meta.url); |
| | const __dirname = dirname(__filename); |
| |
|
| | const { PORT = 7860 } = process.env; |
| |
|
| | const app = express(); |
| |
|
| | |
| | app.use(cors()); |
| |
|
| | |
| | app.use(express.json()); |
| |
|
| | |
| | app.use(express.static('dist/app')); |
| |
|
| | app.use((err: unknown, _req: Request, res: Response, next: NextFunction) => { |
| | if (res.headersSent) { |
| | return next(err); |
| | } |
| | if (isBoom(err)) { |
| | return res.status(err.output.statusCode).json(err.output.payload); |
| | } |
| | next(err); |
| | }); |
| |
|
| | |
| | app.get('*', (_req, res) => { |
| | res.sendFile(join(__dirname, 'app/index.html')); |
| | }); |
| |
|
| | app.listen(PORT, () => { |
| | console.log( |
| | `[${process.env.pm_id ?? ''}]Server listening at http://localhost:${PORT}` |
| | ); |
| | }); |
| |
|