mirror of https://github.com/sundowndev/http.git
feat: support baseUrl and remove port :443 and :80 when http or https (#103)
parent
4e00babc6d
commit
fc3e78e130
|
@ -34,10 +34,17 @@ function httpModule (_moduleOptions) {
|
|||
// Default prefix
|
||||
const prefix = process.env.API_PREFIX || moduleOptions.prefix || '/'
|
||||
|
||||
// Support baseUrl
|
||||
if (moduleOptions.baseUrl && !moduleOptions.baseURL) {
|
||||
moduleOptions.baseURL = moduleOptions.baseUrl
|
||||
|
||||
delete moduleOptions.baseUrl
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
const options = {
|
||||
baseURL: `http://${defaultHost}:${defaultPort}${prefix}`,
|
||||
browserBaseURL: null,
|
||||
browserBaseURL: undefined,
|
||||
proxyHeaders: true,
|
||||
proxyHeadersIgnore: ['accept', 'host', 'cf-ray', 'cf-connecting-ip', 'content-length'],
|
||||
proxy: false,
|
||||
|
@ -62,7 +69,7 @@ function httpModule (_moduleOptions) {
|
|||
}
|
||||
|
||||
// Default browserBaseURL
|
||||
if (!options.browserBaseURL) {
|
||||
if (typeof options.browserBaseURL === 'undefined') {
|
||||
options.browserBaseURL = options.proxy ? prefix : options.baseURL
|
||||
}
|
||||
|
||||
|
@ -77,6 +84,16 @@ function httpModule (_moduleOptions) {
|
|||
options.retry = JSON.stringify(options.retry)
|
||||
}
|
||||
|
||||
// Remove port 443 when https
|
||||
if (options.baseURL.includes('https://')) {
|
||||
options.baseURL = options.baseURL.replace(':443', '')
|
||||
}
|
||||
|
||||
// Remove port 80 when http
|
||||
if (options.baseURL.includes('http://')) {
|
||||
options.baseURL = options.baseURL.replace(':80', '')
|
||||
}
|
||||
|
||||
// Convert http:// to https:// if https option is on
|
||||
if (options.https === true) {
|
||||
const https = s => s.replace('http://', 'https://')
|
||||
|
|
Loading…
Reference in New Issue