Any roblos url
This commit is contained in:
parent
2be833794a
commit
450de36336
35
index.js
35
index.js
|
@ -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");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) => {
|
}).catch((error) => {
|
||||||
res.status(500).send(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;
|
||||||
|
|
Loading…
Reference in a new issue