1
0
mirror of https://github.com/barthuijgen/factorio-sites.git synced 2025-03-30 23:04:29 +02:00
2021-03-09 18:52:19 +01:00

48 lines
1.1 KiB
TypeScript

import { NextApiHandler } from "next";
const BLOCKED_HEADERS = [
"content-encoding",
"connection",
"server",
"transfer-encoding",
"vary",
"report-to",
"nel",
"expect-ct",
"set-cookie",
"cache-control",
"expires",
];
const handler: NextApiHandler = async (req, res) => {
const path = req.query.proxy ? (req.query.proxy as string[]).join("/") : "";
const result = await fetch(
"https://static-fbe.teoxoy.com/file/factorio-blueprint-editor/" + path
);
result.headers.forEach((val, key) => {
if (
!res.hasHeader(key) &&
!BLOCKED_HEADERS.includes(key) &&
!key.startsWith("x-") &&
!key.startsWith("cf-")
) {
res.setHeader(key, val);
}
});
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("cache-control", "max-age=108000");
if (result.headers.get("content-type") === "application/octet-stream") {
const output = Buffer.from(await result.arrayBuffer());
res.end(output);
} else {
const text = await result.text();
res.end(text);
}
};
export default handler;