diff --git a/routes/apis.js b/routes/apis.js index f594baf..834d7cf 100644 --- a/routes/apis.js +++ b/routes/apis.js @@ -9,7 +9,6 @@ const marked = require('marked'); const markedOptions = utils.markedOptions; const async = require('async'); const cors = require('cors'); -const mustache = require('mustache'); const wicked = require('wicked-sdk'); router.get('/', function (req, res, next) { @@ -80,6 +79,18 @@ function unique(arr) { return a; } +function deduceHostAndSchema(req, apiConfig) { + const nw = req.app.portalGlobals.network; + const host = (apiConfig.api.host) ? apiConfig.api.host : nw.apiHost; + const ssl = (nw.schema == 'https') ? true : false; + let schema = nw.schema; + switch (apiConfig.api.protocol) { + case 'ws:': + case 'wss:': + schema = (ssl) ? 'wss' : 'ws'; + } + return `${schema}://${host}`; +} router.get('/:api', function (req, res, next) { debug("get('/:api')"); @@ -149,10 +160,10 @@ router.get('/:api', function (req, res, next) { // necessary configuration option for any API gateway. // console.log(JSON.stringify(apiConfig)); const apiUris = []; - const nw = req.app.portalGlobals.network; + const host = deduceHostAndSchema(req, apiConfig); for (let u = 0; u < apiConfig.api.uris.length; ++u) { const apiRequestUri = apiConfig.api.uris[u]; - apiUris.push(nw.schema + '://' + nw.apiHost + apiRequestUri); + apiUris.push(`${host}${apiRequestUri}`); } const plans = results.getPlans; diff --git a/views/api.jade b/views/api.jade index ffbc1a7..c8aa668 100644 --- a/views/api.jade +++ b/views/api.jade @@ -127,10 +127,12 @@ block content #apidescription.collapse.panel-collapse.in .panel-body != apiDesc - - a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition » + if apiInfo.auth == "none" + a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?apikey=none&url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition » + else + a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition » - if !authUser + if !authUser && apiInfo.auth != "none" .panel.panel-danger .panel-heading h4.panel-title Not logged in @@ -141,7 +143,7 @@ block content p a(href="/login?redirect=/apis/#{apiInfo.id}").btn.btn-default Log in » - else + else if apiInfo.auth != "none" .panel.panel-default .panel-heading +panelTitle('Applications', '/help/api')