conv. commit
This commit is contained in:
24 files changed
+5159
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { defineConfig } from "astro/config";
|
||||
import svelte from "@astrojs/svelte";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// Dev-only middleware that proxies /api/firmware/* to GitHub releases,
|
||||
// following redirects server-side to avoid CORS issues.
|
||||
function firmwareProxy() {
|
||||
return {
|
||||
name: "firmware-proxy",
|
||||
configureServer(server) {
|
||||
server.middlewares.use(async (req, res, next) => {
|
||||
const match = req.url?.match(
|
||||
/^\/api\/firmware\/([^/]+)\/([^/]+)\/([^/]+)\/(.+)$/,
|
||||
);
|
||||
if (!match) return next();
|
||||
|
||||
const [, owner, repo, tag, filename] = match;
|
||||
const ghUrl = `https://github.com/${owner}/${repo}/releases/download/${tag}/${filename}`;
|
||||
|
||||
try {
|
||||
const resp = await fetch(ghUrl, { redirect: "follow" });
|
||||
if (!resp.ok) {
|
||||
res.writeHead(resp.status);
|
||||
res.end(`GitHub returned ${resp.status}`);
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
"Content-Type": "application/octet-stream",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
});
|
||||
const buffer = Buffer.from(await resp.arrayBuffer());
|
||||
res.end(buffer);
|
||||
} catch (err) {
|
||||
res.writeHead(502);
|
||||
res.end(`Proxy error: ${err}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
integrations: [svelte()],
|
||||
vite: {
|
||||
plugins: [tailwindcss(), firmwareProxy()],
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user