Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Commit bf4fad9

Browse files
committed
Add fallback file support for html5 router
ref: jfhbrook/node-ecstatic#146
1 parent ed8765b commit bf4fad9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

bin/http-server

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ if (argv.h || argv.help) {
2828
" To disable caching, use -c-1.",
2929
"",
3030
" -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com",
31+
" -f --fallback Fallback file name if the request cannot be resolved. e.g.: index.html",
32+
" -a Address to use [0.0.0.0]",
3133
"",
3234
" -S --ssl Enable https.",
3335
" -C --cert Path to ssl cert file (default: cert.pem).",
@@ -44,6 +46,7 @@ var port = argv.p || parseInt(process.env.PORT, 10),
4446
log = (argv.s || argv.silent) ? (function () {}) : console.log,
4547
ssl = !!argv.S || !!argv.ssl,
4648
proxy = argv.P || argv.proxy,
49+
fallback = argv.f || argv.fallback,
4750
requestLogger;
4851

4952
if (!argv.s && !argv.silent) {
@@ -76,7 +79,8 @@ function listen(port) {
7679
robots: argv.r || argv.robots,
7780
ext: argv.e || argv.ext,
7881
logFn: requestLogger,
79-
proxy: proxy
82+
proxy: proxy,
83+
fallbackFile: fallback
8084
};
8185

8286
if (argv.cors) {

lib/http-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var HTTPServer = exports.HTTPServer = function (options) {
2727
this.showDir = options.showDir !== 'false';
2828
this.autoIndex = options.autoIndex !== 'false';
2929
this.contentType = options.contentType || 'application/octet-stream';
30+
this.fallbackFile = options.fallbackFile;
3031

3132
if (options.ext) {
3233
this.ext = options.ext === true
@@ -73,7 +74,8 @@ var HTTPServer = exports.HTTPServer = function (options) {
7374
autoIndex: this.autoIndex,
7475
defaultExt: this.ext,
7576
contentType: this.contentType,
76-
handleError: typeof options.proxy !== 'string'
77+
handleError: typeof options.proxy !== 'string',
78+
fallbackFile: this.fallbackFile
7779
}));
7880

7981
if (typeof options.proxy === 'string') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"colors": "1.0.3",
6262
"optimist": "0.6.x",
6363
"union": "~0.4.3",
64-
"ecstatic": "~0.7.0",
64+
"ecstatic": "ngs/node-ecstatic#fallback-file",
6565
"http-proxy": "^1.8.1",
6666
"portfinder": "0.4.x",
6767
"opener": "~1.4.0",

0 commit comments

Comments
 (0)