Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Make demo badges use utils.fullUrl to handle remote/local port stuff …
Browse files Browse the repository at this point in the history
…better
  • Loading branch information
stenington committed Dec 18, 2013
1 parent 15dc901 commit 93506c8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions controllers/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ var path = require('path');
var configuration = require('../lib/configuration');
var request = require('request');
var awardBadge = require('../lib/award');
var utils = require('../lib/utils');
const logger = require('../lib/logger');

var protocol = configuration.get('protocol') || 'http';
var port = configuration.get('port') || '';
var ORIGIN = protocol + '://' + configuration.get('hostname') + (port ? ':' + port : '');

// Render the view for the demo badge issuer.
exports.issuer = function (req, res) {
res.render('issuer.html', {
Expand All @@ -22,8 +19,8 @@ exports.issuer = function (req, res) {

// Bake & award a demo badge. Uses `demoBadge` below to generate a proper assertion.
exports.award = function (req, res) {
var assertionURL = encodeURIComponent([ORIGIN + '/demo/badge.json', qs.stringify(req.body)].join('?'));
var bakeURL = ORIGIN + '/baker?award=true&assertion=' + assertionURL;
var assertionURL = encodeURIComponent([utils.fullUrl('/demo/badge.json'), qs.stringify(req.body)].join('?'));
var bakeURL = utils.fullUrl('/baker?award=true&assertion=' + assertionURL);

request({url: bakeURL, encoding: 'binary'}, function (err, resp, body) {
res.send(Buffer(body, 'binary'), {'content-type': 'image/png'});
Expand All @@ -40,7 +37,7 @@ exports.massAward = function (req, res) {

fs.readdirSync(demoBadgeDir)
.map(function (f) {
var imgUrl = ORIGIN + '/_demo/' + f;
var imgUrl = utils.fullUrl('/_demo/' + f);
var assertion = makeDemoAssertion(recipient, imgUrl);
return {
baseName: f,
Expand Down Expand Up @@ -102,7 +99,7 @@ function makeDemoAssertion(email, image, title, description) {
criteria: '/demo/criteria',
issuer: {
name: 'Open Badges Demo',
origin: ORIGIN
origin: utils.fullUrl('')
}
}
});
Expand Down

0 comments on commit 93506c8

Please sign in to comment.