Skip to content

Commit

Permalink
Merge pull request #24 from azachwill/devcommit27
Browse files Browse the repository at this point in the history
devcommit27
  • Loading branch information
awilliams1275 authored Aug 19, 2024
2 parents a5bcbbc + b8dc5d0 commit d24d419
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 42 deletions.
4 changes: 2 additions & 2 deletions _build/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ headers = []
[functions."*"]

[[edge_functions]]
function = "hello"
path = "/hello"
function = "redirect_article"
path = "/py/docs"

[[redirects]]
from = "http://shiny.rstudio.com/*"
Expand Down
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ headers = []
[functions."*"]

[[edge_functions]]
function = "hello"
path = "/hello"
function = "redirect_article"
path = "/py/docs"

[[redirects]]
from = "http://shiny.rstudio.com/*"
Expand Down
38 changes: 0 additions & 38 deletions netlify/edge-functions/hello.js

This file was deleted.

23 changes: 23 additions & 0 deletions netlify/edge-functions/redirect_article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default async (request, context) => {
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/*',
};

0 comments on commit d24d419

Please sign in to comment.