]> git.ardis.lu - minimal-routing/commitdiff
Update 404 handling to mirror Cloudflare Pages
authorArdis Lu <ardisglu@gmail.com>
Mon, 21 Mar 2022 03:00:45 +0000 (20:00 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 21 Mar 2022 03:00:45 +0000 (20:00 -0700)
README.md
index.html

index cf6a9a4e4838a21da2406971d91aaa1ce9a1192f..a6c85cde9e18ad434cf414d14c4759ff11360268 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,12 +4,12 @@ Demo website for the minimum JavaScript required to implement client-side routin
 
 ## Web server configuration
 
-This demo website assumes that the web server has been configured to serve `index.html` on all routes **EXCEPT** for the special path: `/errors/404.html`. For `/errors/404.html`, the web server must respond with a `404 Not Found` error and the file `/errors/404.html`.
+This demo website assumes that the web server has been configured to serve `index.html` on all routes **EXCEPT** for the special path: `/errors/NotFound`. For `/errors/NotFound`, the web server must respond with a `404 Not Found` error and the file `/errors/404.html`.
 
-Note: this file path is intentionally nested in a folder because some static site hosts (like [Cloudflare Pages](https://developers.cloudflare.com/pages/platform/serving-pages)) use a top-level `404.html` page as a flag to override the desired behavior of serving `index.html` on all routes.
+Note: this file path is intentionally nested in a folder because some static site hosts (like [Cloudflare Pages](https://developers.cloudflare.com/pages/platform/serving-pages)) use a top-level `404.html` page as a flag to override the desired behavior of serving `index.html` on all other routes.
 
 The desired behavior can be replicated locally using the npm package [local-web-server](https://www.npmjs.com/package/local-web-server):
 
 ```
-ws --spa index.html
+ws --spa index.html --rewrite '/errors/(.*) -> /errors/404.html'
 ```
index 450957a1beefa41c311e24d30e47452d27ee449f..c59c257bec4a691efbff0db029a85401e4e4a176 100644 (file)
@@ -56,7 +56,7 @@
       if (!match) {
         // MUST redirect to a page where the web server serves an actual 404 error (i.e. not just 
         // index.html again) otherwise this triggers an infinite loop
-        window.location.href = `${window.location.protocol}//${window.location.host}/errors/404.html`;
+        window.location.href = `${window.location.protocol}//${window.location.host}/errors/NotFound`;
       }
     }
 
This page took 0.033272 seconds and 4 git commands to generate.