2024-04-09 10:51:05 +00:00
|
|
|
import { startWebSocketServer } from './websocket';
|
|
|
|
import express from 'express';
|
|
|
|
import cors from 'cors';
|
|
|
|
import http from 'http';
|
|
|
|
import routes from './routes';
|
2024-05-13 14:28:17 +00:00
|
|
|
import { getPort } from './config';
|
2024-04-30 06:48:18 +00:00
|
|
|
import logger from './utils/logger';
|
2024-04-20 04:02:19 +00:00
|
|
|
|
|
|
|
const port = getPort();
|
2024-04-09 10:51:05 +00:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const server = http.createServer(app);
|
|
|
|
|
|
|
|
const corsOptions = {
|
|
|
|
origin: '*',
|
|
|
|
};
|
|
|
|
|
|
|
|
app.use(cors(corsOptions));
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
app.use('/api', routes);
|
|
|
|
app.get('/api', (_, res) => {
|
|
|
|
res.status(200).json({ status: 'ok' });
|
|
|
|
});
|
|
|
|
|
2024-05-13 14:28:17 +00:00
|
|
|
server.listen(port, () => {
|
2024-04-30 06:48:18 +00:00
|
|
|
logger.info(`Server is running on port ${port}`);
|
2024-04-09 10:51:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
startWebSocketServer(server);
|
2024-07-30 04:37:28 +00:00
|
|
|
|
|
|
|
process.on('uncaughtException', (err, origin) => {
|
2024-07-31 14:47:57 +00:00
|
|
|
logger.error(`Uncaught Exception at ${origin}: ${err}`);
|
|
|
|
});
|
2024-07-30 04:37:28 +00:00
|
|
|
|
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
2024-07-31 14:47:57 +00:00
|
|
|
logger.error(`Unhandled Rejection at: ${promise}, reason: ${reason}`);
|
|
|
|
});
|