Skip to content

Commit c83fa5e

Browse files
committed
update
1 parent 5b69505 commit c83fa5e

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

app.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,7 @@ app.use(function (err, req, res, next) {
6363
//winstonLogHandler(err);
6464
});
6565

66-
// Middleware to dynamically proxy /api/spawn based on "staging" in the URL
67-
app.use("/api/spawn", (req, res, next) => {
68-
const host = req.hostname || req.headers.host; // Get the request's hostname
69-
const isStaging = host.includes("staging");
70-
71-
console.log(`Incoming URL ${host} is staging is ${isStaging}`);
72-
73-
const target = isStaging
74-
? "https://hoops-staging:11183"
75-
: "https://hoops:11182";
76-
77-
console.log(`Routing /api/spawn request to: ${target}`);
78-
79-
return createProxyMiddleware({
80-
target,
81-
changeOrigin: true,
82-
secure: false, // Allow self-signed certificates
83-
logLevel: "debug",
84-
})(req, res, next);
85-
});
66+
8667

8768
const PORT = process.env.PORT || 443;
8869
server.listen(PORT, () => {

routes/api.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ const fs = require('fs');
66
const path = require('path');
77
const bodyParser = require('body-parser');
88
const { exec, spawn } = require('child_process');
9+
const { createProxyMiddleware } = require('http-proxy-middleware');
10+
11+
router.use("/spawn", (req, res, next) => {
12+
const host = req.hostname || req.headers.host;
13+
const isStaging = host.includes("staging");
14+
15+
console.log(`Incoming URL ${host} is staging: ${isStaging}`);
16+
17+
const target = isStaging
18+
? "https://hoops-staging:11183"
19+
: "https://hoops:11182";
20+
21+
console.log(`Routing /api/spawn request to: ${target}`);
22+
23+
return createProxyMiddleware({
24+
target,
25+
changeOrigin: true,
26+
secure: false,
27+
logLevel: "debug",
28+
})(req, res, next);
29+
});
930

1031
const throttle_options = {
1132
'rate': '5/s',
@@ -14,6 +35,7 @@ const throttle_options = {
1435
}
1536
};
1637

38+
1739
router.use((req, res, next) => {
1840
if (req.body.cognito_auth_token) {
1941
req.auth = { header: 'X-Cognito-Access-Token', token: req.body.cognito_auth_token };

0 commit comments

Comments
 (0)