Skip to content

Commit 04dc4a0

Browse files
authored
Merge pull request BrasilAPI#64 from filipedeschamps/mock-correios-service
feat(browser): use a mock Correios service only on browser build
2 parents e139c53 + 5cd1f8a commit 04dc4a0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
]
3333
]
3434
},
35+
"browser": {
36+
"./src/services/correios.js": "./src/services/correios-browser-mock.js"
37+
},
3538
"repository": {
3639
"type": "git",
3740
"url": "https://github.com/filipedeschamps/cep-promise.git"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
import ServiceError from '../errors/service.js'
4+
5+
/*
6+
* This is a mock service to be used when Browserify
7+
* renders the distribution file. Correios service
8+
* doesn't support CORS, so there's no reason to
9+
* include the original file with it's (heavy)
10+
* dependencies like "xml2js"
11+
*/
12+
13+
function fetchCorreiosService (cepWithLeftPad) {
14+
15+
return new Promise((resolve, reject) => {
16+
const serviceError = new ServiceError({
17+
message: 'O serviço dos Correios não aceita requests via Browser (CORS).',
18+
service: 'correios'
19+
})
20+
21+
reject(serviceError)
22+
})
23+
}
24+
25+
26+
export default fetchCorreiosService

0 commit comments

Comments
 (0)