Skip to content

Commit

Permalink
fix: generate correct routes for trailingSlash config
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Nov 3, 2023
1 parent 45fd667 commit d98e351
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions __snapshots__/generate.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ location ~ ^/(?:/)?$ {
}
location ~ ^/hello(?:/)?$ {
try_files /hello.html /index.html;
try_files /hello/index.html /index.html;
}
location ~ ^/hello/world(?:/)?$ {
try_files /hello/world.html /index.html;
try_files /hello/world/index.html /index.html;
}
location ~ ^/([^/]+?)(?:/)?$ {
try_files /[foo].html /index.html;
try_files /[foo]/index.html /index.html;
}
location ~ ^/([^/]+?)/([^/]+?)/hello(?:/)?$ {
try_files /[foo]/[bar]/hello.html /index.html;
try_files /[foo]/[bar]/hello/index.html /index.html;
}
location ~ ^/([^/]+?)/([^/]+?)/([^/]+?)(?:/)?$ {
try_files /[foo]/[bar]/[id].html /index.html;
try_files /[foo]/[bar]/[id]/index.html /index.html;
}"
`;
8 changes: 5 additions & 3 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const { config } = JSON.parse(readFileSync(requiredServerFiles, "utf-8"));

const routes = staticRoutes.concat(dynamicRoutes).map((route) => {
let { page, regex } = route;
regex = `^${basePath || ""}${regex.slice(1)}`;

if (route.page === "/") {
page = "/index";
regex = basePath ? `^${basePath}${regex.slice(2)}` : regex;
} else if (config.trailingSlash) {
page = `${route.page}/index`;
} else {
if (config.trailingSlash) {
page = `${route.page}/index`;
}
regex = `^${basePath || ""}${regex.slice(1)}`;
}

return `
Expand Down

0 comments on commit d98e351

Please # to comment.