Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit de46911

Browse files
committed
feat: add a new middleware to proxy api requests through workers
1 parent 64d7677 commit de46911

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

functions/api/_middleware.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const onRequest: PagesFunction = async (context) => {
2+
const {
3+
request, // same as existing Worker API
4+
env, // same as existing Worker API
5+
params, // if filename includes [id] or [[path]]
6+
waitUntil, // same as ctx.waitUntil in existing Worker API
7+
next, // used for middleware or to fetch assets
8+
data, // arbitrary space for passing data between middlewares
9+
} = context
10+
const url = new URL(request.url);
11+
12+
url.protocol = 'https:'
13+
url.hostname = 'api.lilnouns.dev';
14+
url.pathname = url.pathname.slice(4);
15+
url.port = '443';
16+
17+
return fetch(url.toString(), request);
18+
};

0 commit comments

Comments
 (0)