Skip to content

Commit

Permalink
Merge a158e93 into 5dedef8
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambie committed Oct 29, 2018
2 parents 5dedef8 + a158e93 commit 8213bb3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
20 changes: 20 additions & 0 deletions config.js
Expand Up @@ -68,6 +68,26 @@ const schema = {
env: 'SSL_INTERMEDIATE_CERTIFICATE_PATHS'
}
},
publicUrl: {
host: {
doc: 'The host of the URL where the CDN instance can be publicly accessed at',
format: '*',
default: null,
env: 'URL_HOST'
},
port: {
doc: 'The port of the URL where the CDN instance can be publicly accessed at',
format: '*',
default: 80,
env: 'URL_PORT'
},
protocol: {
doc: 'The protocol of the URL where the CDN instance can be publicly accessed at',
format: 'String',
default: 'http',
env: 'URL_PROTOCOL'
}
},
logging: {
enabled: {
doc: 'If true, logging is enabled using the following settings.',
Expand Down
6 changes: 5 additions & 1 deletion dadi/lib/index.js
Expand Up @@ -365,13 +365,17 @@ Server.prototype.status = function (req, res, next) {
return next()
}

let baseUrl = config.get('publicUrl.host')
? `${config.get('publicUrl.protocol')}://${config.get('publicUrl.host')}:${config.get('publicUrl.port')}`
: `http://${config.get('server.host')}:${config.get('server.port')}`

let params = {
site: site,
package: '@dadi/cdn',
version: version,
healthCheck: {
authorization: authorization,
baseUrl: `http://${config.get('server.host')}:${config.get('server.port')}`,
baseUrl,
routes: config.get('status.routes')
}
}
Expand Down
54 changes: 52 additions & 2 deletions test/acceptance/status.js
@@ -1,8 +1,7 @@
var _ = require('underscore')
var fs = require('fs')
var path = require('path')
var nock = require('nock')
var should = require('should')
var sinon = require('sinon')
var request = require('supertest')

var cache = require(__dirname + '/../../dadi/lib/cache')
Expand Down Expand Up @@ -59,6 +58,57 @@ describe('Status', function () {
done()
})

describe('Base URL', function () {
beforeEach(function (done) {
updateConfigAndReloadApp({
publicUrl: {
host: 'www.example.com',
port: 80
}
})

let statusScope = nock('http://www.example.com')
.get('/test.jpg?format=png&quality=50&width=800&height=600')
.reply(200)

app.start(function (err) {
if (err) return done(err)

// give http.Server a moment to finish starting up
// then grab a bearer token from it
setTimeout(function () {
help.getBearerToken(function (err, token) {
if (err) return done(err)
bearerToken = token
done()
})
}, 500)
})
})

afterEach(function (done) {
help.clearCache()
app.stop(done)
})

it('should use publicUrl as base for status checks, if configured', function (done) {
var client = request('http://' + config.get('server.host') + ':' + config.get('server.port'))
client
.post(statusRoute)
.set('Authorization', 'Bearer ' + bearerToken)
.expect('content-type', 'application/json')
.expect(200)
.end((err, res) => {
console.log('res :', res)

let statusResponse = res.body

statusResponse.status.status.should.eql(200)
done()
})
})
})

describe('Integrated', function () {
describe('Authenticated', function () {
beforeEach(function (done) {
Expand Down

0 comments on commit 8213bb3

Please sign in to comment.