mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-28 14:29:04 +01:00
add more liks
This commit is contained in:
parent
ccba3c86b5
commit
d0c57e8f09
1 changed files with 25 additions and 21 deletions
46
p/server.js
46
p/server.js
|
@ -4,18 +4,21 @@ const { URL } = require("url");
|
||||||
|
|
||||||
// Array of hostnames that will be proxied
|
// Array of hostnames that will be proxied
|
||||||
const URL_WHITELIST = [
|
const URL_WHITELIST = [
|
||||||
'i.ytimg.com',
|
"i.ytimg.com",
|
||||||
'yt3.googleusercontent.com',
|
"yt3.googleusercontent.com",
|
||||||
'cdn.glitch.global',
|
"cdn.glitch.global",
|
||||||
'cdn.statically.io',
|
"cdn.statically.io",
|
||||||
'site-assets.fontawesome.com',
|
"site-assets.fontawesome.com",
|
||||||
'fonts.gstatic.com',
|
"fonts.gstatic.com",
|
||||||
'yt3.ggpht.com',
|
"yt3.ggpht.com",
|
||||||
'tube.kuylar.dev',
|
"tube.kuylar.dev",
|
||||||
'lh3.googleusercontent.com',
|
"lh3.googleusercontent.com",
|
||||||
'is4-ssl.mzstatic.com',
|
"is4-ssl.mzstatic.com",
|
||||||
'twemoji.maxcdn.com',
|
"is2-ssl.mzstatic.com",
|
||||||
'unpkg.com',
|
"is1-ssl.mzstatic.com",
|
||||||
|
"is3-ssl.mzstatic.com",
|
||||||
|
"twemoji.maxcdn.com",
|
||||||
|
"unpkg.com",
|
||||||
];
|
];
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
@ -24,7 +27,7 @@ app.use(express.json()); // for parsing application/json
|
||||||
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
console.log(`=> ${req.method} ${req.originalUrl.slice(1)}`)
|
console.log(`=> ${req.method} ${req.originalUrl.slice(1)}`);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,8 +37,8 @@ app.use(function (req, res, next) {
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {express.Request} req
|
* @param {express.Request} req
|
||||||
* @param {express.Response} res
|
* @param {express.Response} res
|
||||||
*/
|
*/
|
||||||
const proxy = async (req, res) => {
|
const proxy = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
@ -43,9 +46,9 @@ const proxy = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = new URL("https://" + req.originalUrl.slice(10));
|
url = new URL("https://" + req.originalUrl.slice(10));
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log('==> Cannot parse URL: ' + e);
|
console.log("==> Cannot parse URL: " + e);
|
||||||
return res.status(400).send('Malformed URL');
|
return res.status(400).send("Malformed URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!URL_WHITELIST.includes(url.host)) {
|
if (!URL_WHITELIST.includes(url.host)) {
|
||||||
|
@ -61,9 +64,10 @@ const proxy = async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
f.body.pipe(res);
|
f.body.pipe(res);
|
||||||
} catch(e) {
|
|
||||||
|
} catch (e) {
|
||||||
console.log(`==> Error: ${e}`);
|
console.log(`==> Error: ${e}`);
|
||||||
res.status(500).send('Internal server error');
|
res.status(500).send("Internal server error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,4 +81,4 @@ app.get("/", (req, res) =>
|
||||||
|
|
||||||
app.all("/*", listener);
|
app.all("/*", listener);
|
||||||
|
|
||||||
app.listen(3000, () => console.log('Listening on 0.0.0.0:3000'));
|
app.listen(3000, () => console.log("Listening on 0.0.0.0:3000"));
|
||||||
|
|
Loading…
Reference in a new issue