Skip to content

Commit f9633e2

Browse files
committed
Host test case added
1 parent 846a3b1 commit f9633e2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/core/Util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { platform, release } from 'os'
2+
const HOST_REGEX = /^(?!\w+:\/\/)([\w-:]+\.)+([\w-:]+)(?::(\d+))?(?!:)$/
3+
4+
export function isHost (host) {
5+
return HOST_REGEX.test(host)
6+
}
27

38
export function isNode () {
49
return typeof process !== 'undefined' && !process.browser

lib/core/contentstackHTTPClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import clonedeep from 'lodash/cloneDeep'
22
import Qs from 'qs'
33
import axios from 'axios'
44
import contentstackRetry from './contentstack-retry'
5-
const HOST_REGEX = /^(?!\w+:\/\/)([^\s:]+\.[^\s:]+)(?::(\d+))?(?!:)$/
5+
import { isHost } from './Util'
66

77
export default function contentstackHttpClient (options) {
88
const defaultConfig = {
@@ -40,10 +40,10 @@ export default function contentstackHttpClient (options) {
4040

4141
const protocol = config.insecure ? 'http' : 'https'
4242
let hostname = config.defaultHostName
43-
let port = 443
44-
const version = 'v3'
43+
let port = config.port || 443
44+
const version = config.version || 'v3'
4545

46-
if (HOST_REGEX.test(config.host)) {
46+
if (isHost(config.host)) {
4747
const parsed = config.host.split(':')
4848
if (parsed.length === 2) {
4949
[hostname, port] = parsed

0 commit comments

Comments
 (0)