feat: fork worker

This commit is contained in:
karishmas6
2024-10-07 01:37:50 +05:30
parent c714d6df5d
commit ee453b9069

View File

@@ -14,6 +14,7 @@ import csrf from 'csurf';
import { SERVER_PORT } from "./constants/config";
import { Server } from "socket.io";
import { readdirSync } from "fs"
import { fork } from 'child_process';
const csrfProtection = csrf({ cookie: true })
@@ -60,6 +61,17 @@ readdirSync(path.join(__dirname, 'api')).forEach((r) => {
}
});
const workerProcess = fork(path.resolve(__dirname, './worker.ts'));
workerProcess.on('message', (message) => {
console.log('Message from worker:', message);
});
workerProcess.on('error', (error) => {
console.error(`Worker error: ${error}`);
});
workerProcess.on('exit', (code) => {
console.log(`Worker exited with code: ${code}`);
});
app.get('/', function (req, res) {
return res.send('Maxun server started 🚀');
});