Any roblos url

This commit is contained in:
Christopher Cookman 2024-08-05 15:33:30 -06:00
parent 2be833794a
commit 450de36336
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -1,6 +1,10 @@
const express = require('express'); const express = require('express');
const axios = require('axios'); const axios = require('axios');
const allowedDomains = [
"roblox.com"
]
const app = express(); const app = express();
const rateLimit = require("express-rate-limit"); const rateLimit = require("express-rate-limit");
@ -11,18 +15,27 @@ app.use(rateLimit({
keyGenerator: (req) => req.headers["x-forwarded-for"] || req.connection.remoteAddress, keyGenerator: (req) => req.headers["x-forwarded-for"] || req.connection.remoteAddress,
})); }));
app.get("/*", (req, res) => { app.get("/:domain/*", (req, res) => {
// get the full path with arguments and proxy it to https://api.roblox.com/ // get the domain and the rest of the path+args
const path = req.path; const domain = req.params.domain;
const url = `https://apis.roblox.com${path}`; const path = req.params[0];
console.log(`Proxying request to ${url}`); const args = req.query;
// get the response from the url and send it back to the client // Check that domain is equal or subdomain of allowedDomains
axios.get(url).then((response) => { if (!allowedDomains.some((allowedDomain) => domain.endsWith(allowedDomain))) {
res.send(response.data); res.status(403).send("Domain not allowed");
}).catch((error) => { return;
res.status(500).send(error); }
})
// Make the request
axios.get(`https://${domain}/${path}`, {
params: args
}).then((response) => {
// Send the response back
res.status(response.status).send(response.data);
}).catch((error) => {
// Send the error back
res.status(error.response.status).send(error.response.data);
});
}); });
const port = process.env.SERVER_PORT || 3000; const port = process.env.SERVER_PORT || 3000;