-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65ddbe1
commit 4ddc86a
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// functions/_middleware.ts | ||
export async function onRequest({ request, next }: any) { | ||
const url = new URL(request.url); | ||
|
||
// If the hostname ends with poap.in | ||
if (url.hostname.endsWith('poap.in')) { | ||
const subdomain = url.hostname.split('.')[0]; | ||
if (subdomain !== 'www' && subdomain !== '') { | ||
// Rewrite the path | ||
url.pathname = `/v/${subdomain}.eth${url.pathname}`; | ||
request = new Request(url, request); | ||
} | ||
} | ||
|
||
// If the request is for assets or API, proxy to the original site | ||
if (url.pathname.startsWith('/assets/') || url.pathname.startsWith('/api/')) { | ||
const targetUrl = `https://poap.in${url.pathname}${url.search}`; | ||
return fetch(targetUrl, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body, | ||
}); | ||
} | ||
|
||
return next(); | ||
} |