forked from CybriaTech/CybriaGG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (46 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const http = require('http');
const httpProxy = require('http-proxy');
const express = require('express');
const path = require('path');
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Slave ${process.pid} is running`);
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`Slave ${worker.process.pid} died`);
cluster.fork();
});
} else {
const app = express();
const nggurl = 'https://educationbluesky.com';
const proxy = httpProxy.createProxyServer({
target: nggurl,
changeOrigin: true,
});
app.use('/', (req, res) => {
console.log(`Incoming Requests: ${req.url}`);
proxy.web(req, res);
});
app.use((req, res, next) => {
res.setHeader('Content-Security-Policy', 'default-src "self"; style-src "self"');
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('X-XSS-Protection', '1; mode=block');
res.setHeader('Content-Type', 'text/html');
next();
});
const server = http.createServer(app);
const PORT = 8080;
server.listen(PORT, () => {
console.log(`CybriaGG Slave ${process.pid} has been successfully run! On Port ${PORT}`);
});
process.on('unhandledRejection', (reason, promise) => {
console.error(`Slave ${process.pid} detected unhandled rejections:`, promise, 'reason:', reason);
});
process.on('uncaughtException', (err) => {
console.error(`Slave ${process.pid} uncaught exception:`, err);
});
}