Skip to content

Commit

Permalink
Merge pull request #87 from SparkartGroupInc/provide-url-data-in-context
Browse files Browse the repository at this point in the history
Provide url data in context
#79
  • Loading branch information
Fauntleroy committed Feb 19, 2014
2 parents d16ac4a + 0128663 commit ef43a35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,17 @@ var Page = function( page_path, options ){

// generates the page's markup
this.render = function( req, res, options ){

if( server.options.log_level >= 2 ) var start_serve = new Date;
options = options || {};
// generate url data to be served in context
var href = req.protocol +'://'+ req.get('host') + req.url;
var url_data = url.parse( href, true );
url_data = _.pick( url_data, 'host', 'port', 'hostname', 'hash', 'search', 'query', 'pathname', 'path', 'href' );
url_data.origin = req.protocol +'//'+ url_data.host;

var context = {
url: url_data,
page: {
path: this.path,
title: this.title,
Expand Down
13 changes: 13 additions & 0 deletions test/solidus.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ describe( 'Solidus', function(){
});
});

it( 'Makes URL information available in page context', function( done ){
var s_request = request( solidus_server.router );
s_request.get('/.json')
.expect( 'Content-Type', /json/ )
.expect( 200 )
.end( function( err, res ){
assert( res.body.url );
assert( res.body.url.path === '/.json' );
if( err ) throw err;
done();
});
});

it( 'Fetches resources and adds them to the page context', function( done ){
var s_request = request( solidus_server.router );
async.parallel([
Expand Down

0 comments on commit ef43a35

Please sign in to comment.