Skip to content

Commit

Permalink
Use send for fallback (#205)
Browse files Browse the repository at this point in the history
* Use send to transfer fallback file

* Updating send version to match serve-static
  • Loading branch information
andrewiggins authored and justinmchase committed Nov 22, 2016
1 parent 9398092 commit 2027a3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -47,6 +47,7 @@
"connect-livereload": "^0.5.4",
"event-stream": "^3.3.2",
"gulp-util": "^3.0.6",
"send": "^0.13.2",
"tiny-lr": "^0.2.1"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/index.coffee
Expand Up @@ -6,6 +6,7 @@ https = require("https")
fs = require("fs")
connect = require("connect")
liveReload = require("connect-livereload")
send = require("send")
tiny_lr = require("tiny-lr")
apps = []

Expand Down Expand Up @@ -135,7 +136,7 @@ class ConnectApp
if typeof @fallback is "function"
fallbackPath = @fallback(req, res)

require('fs').createReadStream(fallbackPath).pipe(res)
send(req, fallbackPath).pipe(res);

return steps

Expand Down
5 changes: 3 additions & 2 deletions test/test.js
Expand Up @@ -150,11 +150,12 @@ describe('gulp-connect', function () {
})
it('Fallback test', function (done) {
connect.server({
fallback: __dirname + '/fixtures/simplest/test.txt'
fallback: __dirname + '/fixtures/simplest/index.html'
});
request('http://localhost:8080')
.get('/not/existing/path')
.expect(/Hello world/)
.expect(/index page/)
.expect('Content-Type', new RegExp('text/html; charset=UTF-8'))
.expect(200)
.end(function (err, res) {
connect.serverClose();
Expand Down

0 comments on commit 2027a3c

Please sign in to comment.