diff --git a/__snapshots__/generate.test.js.snap b/__snapshots__/generate.test.js.snap index c470da8..8133108 100644 --- a/__snapshots__/generate.test.js.snap +++ b/__snapshots__/generate.test.js.snap @@ -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; }" `; diff --git a/generate.js b/generate.js index bbe88f7..c9f0dbf 100644 --- a/generate.js +++ b/generate.js @@ -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 `