Skip to content

Commit

Permalink
Merge pull request BrasilAPI#130 from filipedeschamps/fixes-browser-i…
Browse files Browse the repository at this point in the history
…mport

Correção do import usando module bundlers no navegador (segunda tentativa)
  • Loading branch information
filipedeschamps authored Nov 27, 2018
2 parents 9666ca9 + caf3b8b commit 5bda527
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 8 deletions.
405 changes: 405 additions & 0 deletions dist/cep-promise-browser.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/cep-promise-browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions dist/cep-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function ServiceError() {

ServiceError.prototype = new Error();

var PROXY_URL = 'https://proxier.now.sh/';
var CEP_ABERTO_TOKEN = '37d718d2984e6452584a76d3d59d3a26';

function fetchCepAbertoService(cepWithLeftPad) {
var proxyURL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

Expand All @@ -41,7 +44,7 @@ function fetchCepAbertoService(cepWithLeftPad) {
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8',
'Authorization': 'Token token="37bfda18fd4b423cdb6748d14ba30aa6"'
'Authorization': 'Token token=' + CEP_ABERTO_TOKEN
}
};

Expand Down Expand Up @@ -216,8 +219,6 @@ function throwApplicationError$2(error) {
throw serviceError;
}

var PROXY_URL = 'https://cors-anywhere.herokuapp.com/';

/* istanbul ignore next */
function injectProxy(Service) {
return function (cepWithLeftPad) {
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.0.3",
"description": "Busca por CEP integrado diretamente aos serviços dos Correios e ViaCEP",
"main": "dist/cep-promise.min.js",
"module": "dist/cep-promise.min.js",
"module": "dist/cep-promise-browser.min.js",
"scripts": {
"test": "npm run build && npm run coverage",
"coverage": "babel-node node_modules/.bin/babel-istanbul cover _mocha -- --timeout 60000 test/**/*.spec.js",
Expand All @@ -13,9 +13,12 @@
"test-e2e-watch": "mocha --watch --compilers js:babel-core/register test/e2e/**/*.spec.js",
"lint-check": "standard",
"lint-fix": "standard --fix",
"build": "rollup -c && uglifyjs dist/cep-promise.js -cm -o dist/cep-promise.min.js",
"build-browser": "rollup -c && uglifyjs dist/cep-promise-browser.js -cm -o dist/cep-promise-browser.min.js",
"build-node": "rollup -c && uglifyjs dist/cep-promise.js -cm -o dist/cep-promise.min.js",
"build": "npm run build-browser && npm run build-node",
"prepublish": "npm run build"
},
"browser": "dist/cep-promise-browser.min.js",
"repository": {
"type": "git",
"url": "https://github.com/filipedeschamps/cep-promise.git"
Expand Down
19 changes: 19 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'

const input = 'src/cep-promise.js'
const defaultPlugins = [
Expand All @@ -21,5 +22,23 @@ export default [
format: 'umd',
name: 'cep'
}
},
{
input,
plugins: [].concat(defaultPlugins, [
resolve({
browser: true
}),
commonjs()
]),
context: 'window',
output: {
file: 'dist/cep-promise-browser.js',
format: 'umd',
name: 'cep'
}
}
]



3 changes: 2 additions & 1 deletion src/services/cepaberto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fetch from 'isomorphic-unfetch'
import ServiceError from '../errors/service.js'
import { CEP_ABERTO_TOKEN } from '../utils/consts'

export default function fetchCepAbertoService (cepWithLeftPad, proxyURL = '') {
const url = `${proxyURL}http://www.cepaberto.com/api/v2/ceps.json?cep=${cepWithLeftPad}`
Expand All @@ -10,7 +11,7 @@ export default function fetchCepAbertoService (cepWithLeftPad, proxyURL = '') {
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8',
'Authorization': 'Token token="37bfda18fd4b423cdb6748d14ba30aa6"'
'Authorization': `Token token=${CEP_ABERTO_TOKEN}`
}
}

Expand Down
Loading

0 comments on commit 5bda527

Please sign in to comment.