-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af3e64e
commit baea069
Showing
5 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function (req, res, next) { | ||
req.param2 = 'overwritten'; | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= request.param1 %>, <%= request.param2 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
var express = require('express'); | ||
var http = require('http'); | ||
var serveSpa = require('../../lib/index.js'); | ||
var path = require('path'); | ||
var rp = require('request-promise'); | ||
|
||
|
||
describe('Regarding the beforeAll hook, Serve-SPA', function () { | ||
|
||
var server; | ||
|
||
before(function (done) { | ||
var app = express(); | ||
serveSpa(app, path.join(__dirname, '../fixtures/serve/'), { | ||
|
||
beforeAll: function (req, res, next) { | ||
|
||
switch (req.path) { | ||
case '/beforeAll-hook/own': | ||
res.send('own'); | ||
return; | ||
case '/beforeAll-hook/redirect': | ||
res.redirect('http://localhost:4000/sub1/'); | ||
return; | ||
} | ||
|
||
req.param1 = 'original param1'; | ||
req.param2 = 'original param2'; | ||
next(); | ||
|
||
} | ||
|
||
}); | ||
server = http.createServer(app); | ||
server.listen(4000, function () { done(); }); | ||
}); | ||
|
||
after(function () { | ||
server.close(); | ||
}); | ||
|
||
|
||
it('should call the beforeAll middleware first', function () { | ||
|
||
return rp('http://localhost:4000/beforeAll-hook') | ||
.then(function (body) { | ||
expect(body).to.equal('original param1, overwritten'); | ||
}); | ||
|
||
}); | ||
|
||
it('should allow serving its own response', function () { | ||
|
||
return rp('http://localhost:4000/beforeAll-hook/own') | ||
.then(function (body) { | ||
expect(body).to.equal('own'); | ||
}); | ||
|
||
}); | ||
|
||
it('should allow a redirect', function () { | ||
|
||
return rp('http://localhost:4000/beforeAll-hook/redirect') | ||
.then(function (body) { | ||
expect(body).to.equal('sub1'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters