@@ -5,12 +5,9 @@ var path = require('path');
55var configuration = require ( '../lib/configuration' ) ;
66var request = require ( 'request' ) ;
77var awardBadge = require ( '../lib/award' ) ;
8+ var utils = require ( '../lib/utils' ) ;
89const logger = require ( '../lib/logger' ) ;
910
10- var protocol = configuration . get ( 'protocol' ) || 'http' ;
11- var port = configuration . get ( 'port' ) || '' ;
12- var ORIGIN = protocol + '://' + configuration . get ( 'hostname' ) + ( port ? ':' + port : '' ) ;
13-
1411// Render the view for the demo badge issuer.
1512exports . issuer = function ( req , res ) {
1613 res . render ( 'issuer.html' , {
@@ -22,8 +19,8 @@ exports.issuer = function (req, res) {
2219
2320// Bake & award a demo badge. Uses `demoBadge` below to generate a proper assertion.
2421exports . award = function ( req , res ) {
25- var assertionURL = encodeURIComponent ( [ ORIGIN + '/demo/badge.json' , qs . stringify ( req . body ) ] . join ( '?' ) ) ;
26- var bakeURL = ORIGIN + '/baker?award=true&assertion=' + assertionURL ;
22+ var assertionURL = encodeURIComponent ( [ utils . fullUrl ( '/demo/badge.json' ) , qs . stringify ( req . body ) ] . join ( '?' ) ) ;
23+ var bakeURL = utils . fullUrl ( '/baker?award=true&assertion=' + assertionURL ) ;
2724
2825 request ( { url : bakeURL , encoding : 'binary' } , function ( err , resp , body ) {
2926 res . send ( Buffer ( body , 'binary' ) , { 'content-type' : 'image/png' } ) ;
@@ -40,7 +37,7 @@ exports.massAward = function (req, res) {
4037
4138 fs . readdirSync ( demoBadgeDir )
4239 . map ( function ( f ) {
43- var imgUrl = ORIGIN + '/_demo/' + f ;
40+ var imgUrl = utils . fullUrl ( '/_demo/' + f ) ;
4441 var assertion = makeDemoAssertion ( recipient , imgUrl ) ;
4542 return {
4643 baseName : f ,
@@ -102,7 +99,7 @@ function makeDemoAssertion(email, image, title, description) {
10299 criteria : '/demo/criteria' ,
103100 issuer : {
104101 name : 'Open Badges Demo' ,
105- origin : ORIGIN
102+ origin : utils . fullUrl ( '' )
106103 }
107104 }
108105 } ) ;
0 commit comments