From 2686b7101726643ac1f1e92172aab56087924d80 Mon Sep 17 00:00:00 2001 From: Carlos Guedes Date: Sun, 6 Nov 2016 18:01:38 +0000 Subject: [PATCH] Feature: Allow to specify a pathname only URL for swagger spec (#152) --- sampleapp/basepath/index.js | 2 +- src/infrastructure/Url.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sampleapp/basepath/index.js b/sampleapp/basepath/index.js index 7e40862..dca8adf 100644 --- a/sampleapp/basepath/index.js +++ b/sampleapp/basepath/index.js @@ -2,7 +2,7 @@ import APIExplorer from './../../src' import AddLinksPlugin from './plugin' APIExplorer - .addAPI('petstore', 'swagger2', `${window.location.protocol}//${window.location.host}/sampleapp/petstore/petstore.json`, c => { + .addAPI('petstore', 'swagger2', `/sampleapp/petstore/petstore.json`, c => { c.useProxy(true) }) .addPlugin(AddLinksPlugin) diff --git a/src/infrastructure/Url.js b/src/infrastructure/Url.js index bd6f6e4..c74ffbe 100644 --- a/src/infrastructure/Url.js +++ b/src/infrastructure/Url.js @@ -2,6 +2,13 @@ const URI_PROTOCOL_REGEX = /([a-z]+):\/\// class Url { constructor (url) { + if (url.startsWith('/')) { + console.log('Converting pathname only URL to URL with protocol and host.') + console.log(`Current url: ${url}`) + url = `${window.location.protocol}//${window.location.host}${url}` + console.log(`Final url: ${url}`) + } + this.url = '' this.queryString = '' this.useProxy = false