This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8594788
commit 632cd2f
Showing
1 changed file
with
14 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,20 @@ | ||
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; | ||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
if (cluster.isMaster) { | ||
console.log(`Slave ${process.pid} is running`); | ||
const app = express(); | ||
|
||
for (let i = 0; i < numCPUs; i++) { | ||
cluster.fork(); | ||
} | ||
const nggUrl = 'https://educationbluesky.com'; | ||
|
||
cluster.on('exit', (worker, code, signal) => { | ||
console.log(`Slave ${worker.process.pid} died`); | ||
cluster.fork(); | ||
}); | ||
} else { | ||
const app = express(); | ||
const proxy = createProxyMiddleware({ | ||
target: nggUrl, | ||
changeOrigin: true, | ||
secure: true, | ||
logLevel: 'debug', | ||
}); | ||
|
||
const nggurl = 'https://mathsspot.com'; | ||
app.use('/', proxy); | ||
|
||
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); | ||
}); | ||
} | ||
const port = process.env.PORT || 8080; | ||
app.listen(port, () => { | ||
console.log(`CybriaGG is running on port ${port}`); | ||
}); |