Skip to content

Commit

Permalink
Allowing preproc.js to export an express.Router()
Browse files Browse the repository at this point in the history
  • Loading branch information
analog-nico committed Dec 23, 2014
1 parent 58d04da commit 498bc1f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -83,8 +83,10 @@ If you want to debug a test you should use `gulp test-without-coverage` to run a

## Change History

- v0.1.1 (2014-12-22)
- Allowing preproc.js to export an `express.Router()`
- v0.1.0 (2014-12-06)
- Initial version
- Initial version

## License (ISC)

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -119,7 +119,7 @@ module.exports = function initServeSpa(app, root, options) {

function render() {

if (arguments.length > 0) {
if ((arguments.length === 1 && arguments[0] !== null) || arguments.length > 1) {
// Error provided or route forward intended...
return next.apply(undefined, arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "serve-spa",
"version": "0.1.0",
"version": "0.1.1",
"description": "Express middleware to serve single page applications in a performant and SEO friendly way",
"keywords": [
"express",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/serve/preproc-with-router/index.htmlt
@@ -0,0 +1 @@
with - <%= req.url %> - <%= req.test %>
19 changes: 19 additions & 0 deletions test/fixtures/serve/preproc-with-router/preproc.js
@@ -0,0 +1,19 @@
'use strict';

var express = require('express');


var router = express.Router();

// FIXME: The router should register relative paths. In this case just /edit/:_id
router.get('/preproc-with-router/edit/:_id', function (req, res, next) {
req.test = req.params._id;
next();
});

router.get('/preproc-with-router/', function (req, res, next) {
req.test = 'base';
next();
});

module.exports = router;
3 changes: 3 additions & 0 deletions test/spec/init.js
Expand Up @@ -66,6 +66,9 @@ describe('Regarding its initialization, Serve-SPA', function () {
'/async-preproc/index.htmlt',
'/async-preproc/preproc.js',
'/index.htmlt',
'/preproc-with-router',
'/preproc-with-router/index.htmlt',
'/preproc-with-router/preproc.js',
'/preproc.js',
'/sub1',
'/sub1/index.htmlt',
Expand Down
9 changes: 9 additions & 0 deletions test/spec/render.js
Expand Up @@ -50,6 +50,15 @@ describe('Regarding rendering the template, Serve-SPA', function () {

});

it('should allow a router to be used for preprocessing', function () {

return rp('http://localhost:4000/preproc-with-router/edit/0123456789')
.then(function (body) {
expect(body).to.equal("with - /preproc-with-router/edit/0123456789 - 0123456789");
});

});

it('should provide req, res, and require for rendering', function () {

return rp('http://localhost:4000/')
Expand Down

0 comments on commit 498bc1f

Please sign in to comment.