-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add null redirect edge functions (#73)
* Add null redirect edge functions * Apply suggestions from code review Co-authored-by: Paulo Borges <[email protected]> --------- Co-authored-by: Paulo Borges <[email protected]>
- Loading branch information
1 parent
c3d3707
commit 3d2348c
Showing
3 changed files
with
31 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -4,4 +4,6 @@ node_modules | |
.idea | ||
.vscode | ||
/docs/ | ||
.bundle | ||
.bundle | ||
# Local Netlify folder | ||
.netlify |
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
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,24 @@ | ||
export default async (request, context) => { | ||
const url = new URL(request.url); | ||
const pathname = url.pathname; | ||
|
||
if (pathname.endsWith('/null') || pathname.endsWith('/null/')) { | ||
// Remove the "/null" part from the URL | ||
let newPathname = pathname.replace(/\/null\/?$/, '/'); | ||
|
||
// Ensure the URL ends with a "/" for local tests | ||
if (!newPathname.endsWith('/')) { | ||
newPathname += '/'; | ||
} | ||
|
||
// Construct the new URL without "/null" | ||
const newUrl = `${url.origin}${newPathname}${url.search}`; | ||
|
||
return Response.redirect(newUrl, 301); | ||
} | ||
|
||
return context.next(); | ||
}; | ||
|
||
// This configures the Edge Function to trigger on paths ending with "/null" | ||
export const config = { path: "*/null" }; |