-
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.
Merge pull request #19 from azachwill/devcommit21
hello
- Loading branch information
Showing
3 changed files
with
25 additions
and
30 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
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 |
---|---|---|
@@ -1,7 +1,26 @@ | ||
export default async (request, context) => { | ||
return new Response("Hello world",{ | ||
headers: { | ||
"content-type": "text/html", | ||
}, | ||
}); | ||
}; | ||
const url = new URL(request.url); | ||
|
||
// Check if the URL path starts with /docs and ends with a trailing slash | ||
if (url.pathname.startsWith('/py/docs') && url.pathname.endsWith('/')) { | ||
// Remove the trailing slash and add .html extension | ||
const newPathname = url.pathname.slice(0, -1) + '.html'; | ||
const newUrl = `${url.origin}${newPathname}${url.search}`; | ||
|
||
// Perform a 301 redirect | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
'Location': newUrl, | ||
}, | ||
}); | ||
} | ||
|
||
// If the URL does not match the criteria, proceed with the request as usual | ||
return context.next(); | ||
}; | ||
|
||
export const config = { | ||
path: '/py/docs/*', | ||
}; | ||
|