Files
parcer/server/src/server.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-05-30 04:49:38 +05:30
import express from 'express';
import http from 'http';
import cors from 'cors';
import 'dotenv/config';
2024-09-17 21:03:15 +05:30
import { record, workflow, storage, auth, integration } from './routes';
2024-05-30 04:49:38 +05:30
import { BrowserPool } from "./browser-management/classes/BrowserPool";
2024-09-23 23:47:10 +05:30
import logger from './logger';
import cookieParser from 'cookie-parser';
import csrf from 'csurf';
2024-05-30 04:49:38 +05:30
import { SERVER_PORT } from "./constants/config";
2024-09-11 13:21:16 +05:30
import { Server } from "socket.io";
2024-05-30 04:49:38 +05:30
2024-09-23 23:47:10 +05:30
const csrfProtection = csrf({ cookie: true })
2024-05-30 04:49:38 +05:30
const app = express();
app.use(cors());
app.use(express.json());
const server = http.createServer(app);
/**
* Globally exported singleton instance of socket.io for socket communication with the client.
* @type {Server}
*/
export const io = new Server(server);
/**
* {@link BrowserPool} globally exported singleton instance for managing browsers.
*/
export const browserPool = new BrowserPool();
2024-09-23 23:47:35 +05:30
// parse cookies - "cookie" is true in csrfProtection
app.use(cookieParser())
2024-09-23 23:47:10 +05:30
app.use(csrfProtection)
app.use('/record', record);
app.use('/workflow', workflow);
app.use('/storage', storage);
2024-09-15 17:57:45 +05:30
app.use('/auth', auth);
2024-09-17 21:03:15 +05:30
app.use('/integration', integration);
2024-05-30 04:49:38 +05:30
app.get('/', function (req, res) {
2024-09-09 05:17:37 +05:30
return res.send('Maxun server started 🚀');
2024-05-30 04:49:38 +05:30
});
2024-09-24 00:05:22 +05:30
app.get('/csrf-token', (req, res) => {
res.json({ csrfToken: req.csrfToken() })
})
2024-09-11 13:21:16 +05:30
server.listen(SERVER_PORT, () => logger.log('info', `Server listening on port ${SERVER_PORT}`));