mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-06 20:28:48 +00:00
first public source commit
This commit is contained in:
parent
1a4fbb9d42
commit
3914fee775
65 changed files with 4697 additions and 312 deletions
29
src/pages/api/proxy.js
Normal file
29
src/pages/api/proxy.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
function pick(object, keys) {
|
||||
return;
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const headers = ["X-API-Key", "Content-Type", "Authorization"].reduce((obj, key) => {
|
||||
if (req.headers && req.headers.hasOwnProperty(key.toLowerCase())) {
|
||||
obj[key] = req.headers[key.toLowerCase()];
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
try {
|
||||
const result = await fetch(req.query.url, {
|
||||
strictSSL: false,
|
||||
rejectUnhauthorized: false,
|
||||
method: req.method,
|
||||
headers: headers,
|
||||
body: req.method == "GET" || req.method == "HEAD" ? null : req.body,
|
||||
}).then((res) => res);
|
||||
|
||||
const forward = await result.text();
|
||||
return res.status(result.status).send(forward);
|
||||
} catch {
|
||||
return res.status(500).send({
|
||||
error: "query failed",
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue