Skip to content

Commit

Permalink
Merge pull request #3 from skewart/config-host-base-url
Browse files Browse the repository at this point in the history
Allow app host and base URL to be configured.
  • Loading branch information
skewart committed Dec 22, 2015
2 parents b62934d + 439c7b5 commit 5ea6604
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var notes = require('./notes');
var platforms = require('./platforms');
var winReleases = require('./win-releases');

function getFullUrl(req) {
return req.protocol + '://' + req.get('host') + req.originalUrl;
function getBaseDownloadUrl(req) {
var requestUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
return url.resolve(requestUrl, req.baseUrl + '/download');
}

// Return a express router
Expand Down Expand Up @@ -158,7 +159,6 @@ module.exports = function nuts(opts) {

// Auto-updates: Status and Squirrel.Mac
router.get('/update/:platform/:version', function(req, res, next) {
var fullUrl = getFullUrl(req);
var platform = req.params.platform;
var tag = req.params.version;

Expand All @@ -182,7 +182,7 @@ module.exports = function nuts(opts) {
var releaseNotes = notes.merge(versions.slice(0, -1), { includeTag: false });

res.status(200).send({
"url": url.resolve(fullUrl, "/download/version/"+latest.tag+"/"+platform+"?filetype=zip"),
"url": getBaseDownloadUrl(req) + '/version/' + latest.tag + '/' + platform + '?filetype=zip',
"name": latest.tag,
"notes": releaseNotes,
"pub_date": latest.published_at.toISOString()
Expand All @@ -194,7 +194,6 @@ module.exports = function nuts(opts) {
// Auto-updates: Squirrel.Windows: serve RELEASES from latest version
// Currently, it will only serve a full.nupkg of the latest release with a normalized filename (for pre-release)
router.get('/update/:platform/:version/RELEASES', function(req, res, next) {
var fullUrl = getFullUrl(req);
var platform = 'win_32';
var tag = req.params.version;

Expand Down Expand Up @@ -227,7 +226,7 @@ module.exports = function nuts(opts) {

// Change filename to use download proxy
.map(function(entry) {
entry.filename = url.resolve(fullUrl, '/download/'+entry.version+'/'+entry.filename);
entry.filename = getBaseDownloadUrl(req) + entry.version+'/'+entry.filename;

return entry;
})
Expand Down

0 comments on commit 5ea6604

Please sign in to comment.