feat: fork worker
This commit is contained in:
@@ -14,6 +14,7 @@ import csrf from 'csurf';
|
|||||||
import { SERVER_PORT } from "./constants/config";
|
import { SERVER_PORT } from "./constants/config";
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
import { readdirSync } from "fs"
|
import { readdirSync } from "fs"
|
||||||
|
import { fork } from 'child_process';
|
||||||
|
|
||||||
const csrfProtection = csrf({ cookie: true })
|
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) {
|
app.get('/', function (req, res) {
|
||||||
return res.send('Maxun server started 🚀');
|
return res.send('Maxun server started 🚀');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user