From 1346d5235b98e4f747ca88143b704b7af708b7da Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 23 May 2016 16:15:00 -0400 Subject: [PATCH] lib/popcorn: update README for `default_file` Signed-off-by: Alexandre Terrasa --- lib/popcorn/README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/popcorn/README.md b/lib/popcorn/README.md index a136621..2bb6646 100644 --- a/lib/popcorn/README.md +++ b/lib/popcorn/README.md @@ -175,6 +175,17 @@ directory from where you launch your app. If you run the app from another directory, it’s safer to use the absolute path of the directory that you want to serve. +In some cases, you can want to redirect request to static files to a default file +instead of returning a 404 error. +This can be achieved by specifying a default file in the StaticHandler: + +~~~ +app.use("/static/", new StaticHandler("public/", "default.html")) +~~~ + +This way all non-matched queries to the StaticHandler will be answered with the +`default.html` file. + ## Advanced Routing **Routing** refers to the definition of application end points (URIs) and how @@ -832,8 +843,13 @@ to your angular controller: import popcorn var app = new App -app.use("/*", new StaticHandler("my-ng-app/")) +app.use("/*", new StaticHandler("my-ng-app/", "index.html")) app.listen("localhost", 3000) ~~~ +Because the StaticHandler will not find the angular routes as static files, +you must specify the path to the default angular controller. +In this example, the StaticHandler will redirect any unknown requests to the `index.html` +angular controller. + See the examples for a more detailed use case working with a JSON API. -- 1.7.9.5