Skip to content

Commit

Permalink
[Docs Site] Add dev-only middleware for /api/ links (#19668)
Browse files Browse the repository at this point in the history
  • Loading branch information
KianNH authored Feb 3, 2025
1 parent fcf1db4 commit 76d401b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineMiddleware } from "astro:middleware";

// `astro dev` only middleware so that `/api/...` links can be viewed.
export const onRequest = defineMiddleware(async (context, next) => {
if (import.meta.env.DEV) {
if (context.url.pathname.startsWith("/api/")) {
const url = new URL(context.url.pathname, import.meta.env.SITE);

return fetch(url, {
headers: {
"accept-encoding": "identity",
},
});
}
}

return next();
});

0 comments on commit 76d401b

Please sign in to comment.