Skip to content

Commit 658f5ea

Browse files
committed
browser: disable proxier
1 parent c9a3b52 commit 658f5ea

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

src/cep-promise.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
'use strict'
22

33
import CepPromiseError from './errors/cep-promise.js'
4-
import {
5-
CorreiosService,
6-
ViaCepService,
7-
WideNetService,
8-
BrasilAPIService
9-
} from './services/index.js'
4+
import { getAvailableServices } from './services/index.js'
105
import Promise from './utils/promise-any.js'
116

127
const CEP_SIZE = 8
@@ -112,12 +107,7 @@ function validateInputLength (cepWithLeftPad) {
112107
}
113108

114109
function fetchCepFromServices (cepWithLeftPad, configurations) {
115-
const providersServices = {
116-
brasilapi: BrasilAPIService,
117-
viacep: ViaCepService,
118-
widenet: WideNetService,
119-
correios: CorreiosService
120-
}
110+
let providersServices = getAvailableServices()
121111

122112
if (configurations.providers.length === 0) {
123113
return Promise.any(

src/services/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ import Correios from './correios'
22
import ViaCep from './viacep'
33
import WideNet from './widenet'
44
import BrasilAPI from './brasilapi.js'
5-
import { PROXY_URL } from '../utils/consts'
65

7-
/* istanbul ignore next */
8-
function isBrowser () {
9-
return typeof window !== 'undefined'
10-
}
6+
export function getAvailableServices () {
7+
const isBrowser = typeof window !== 'undefined'
118

12-
/* istanbul ignore next */
13-
function injectProxy (Service) {
14-
return cepWithLeftPad => Service(cepWithLeftPad, PROXY_URL)
15-
}
9+
if (isBrowser) {
10+
return {
11+
brasilapi: BrasilAPI,
12+
viacep: ViaCep,
13+
widenet: WideNet,
14+
}
15+
}
1616

17-
export const CorreiosService = isBrowser() ? injectProxy(Correios) : Correios
18-
export const ViaCepService = ViaCep
19-
export const WideNetService = WideNet
20-
export const BrasilAPIService = BrasilAPI
17+
return {
18+
brasilapi: BrasilAPI,
19+
viacep: ViaCep,
20+
widenet: WideNet,
21+
correios: Correios
22+
}
23+
}

src/utils/consts.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)