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

Commit

Permalink
Add fallback file support for html5 router
Browse files Browse the repository at this point in the history
  • Loading branch information
ngs committed Aug 12, 2015
1 parent ed8765b commit bf4fad9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if (argv.h || argv.help) {
" To disable caching, use -c-1.",
"",
" -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com",
" -f --fallback Fallback file name if the request cannot be resolved. e.g.: index.html",
" -a Address to use [0.0.0.0]",
"",
" -S --ssl Enable https.",
" -C --cert Path to ssl cert file (default: cert.pem).",
Expand All @@ -44,6 +46,7 @@ var port = argv.p || parseInt(process.env.PORT, 10),
log = (argv.s || argv.silent) ? (function () {}) : console.log,
ssl = !!argv.S || !!argv.ssl,
proxy = argv.P || argv.proxy,
fallback = argv.f || argv.fallback,
requestLogger;

if (!argv.s && !argv.silent) {
Expand Down Expand Up @@ -76,7 +79,8 @@ function listen(port) {
robots: argv.r || argv.robots,
ext: argv.e || argv.ext,
logFn: requestLogger,
proxy: proxy
proxy: proxy,
fallbackFile: fallback
};

if (argv.cors) {
Expand Down
4 changes: 3 additions & 1 deletion lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var HTTPServer = exports.HTTPServer = function (options) {
this.showDir = options.showDir !== 'false';
this.autoIndex = options.autoIndex !== 'false';
this.contentType = options.contentType || 'application/octet-stream';
this.fallbackFile = options.fallbackFile;

if (options.ext) {
this.ext = options.ext === true
Expand Down Expand Up @@ -73,7 +74,8 @@ var HTTPServer = exports.HTTPServer = function (options) {
autoIndex: this.autoIndex,
defaultExt: this.ext,
contentType: this.contentType,
handleError: typeof options.proxy !== 'string'
handleError: typeof options.proxy !== 'string',
fallbackFile: this.fallbackFile
}));

if (typeof options.proxy === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"colors": "1.0.3",
"optimist": "0.6.x",
"union": "~0.4.3",
"ecstatic": "~0.7.0",
"ecstatic": "ngs/node-ecstatic#fallback-file",
"http-proxy": "^1.8.1",
"portfinder": "0.4.x",
"opener": "~1.4.0",
Expand Down

0 comments on commit bf4fad9

Please sign in to comment.