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

Commit cf061c3

Browse files
Merge pull request #983 from stenington/fix-demo-badges
Make demo badges use utils.fullUrl to handle remote/local port stuff better
2 parents 15dc901 + 93506c8 commit cf061c3

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

controllers/demo.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ var path = require('path');
55
var configuration = require('../lib/configuration');
66
var request = require('request');
77
var awardBadge = require('../lib/award');
8+
var utils = require('../lib/utils');
89
const 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.
1512
exports.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.
2421
exports.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

Comments
 (0)