-
-
Save shaci/0b8bcff92d0817d8ed74b74d9bf4d282 to your computer and use it in GitHub Desktop.
Revisions
-
brenopolanski revised this gist
Sep 29, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -101,6 +101,7 @@ Use if u need **References**: - https://cli.vuejs.org/config/#devserver-proxy - http://vuejs-templates.github.io/webpack/proxy.html - https://github.com/axios/axios/issues/853#issuecomment-374846375 - https://stackoverflow.com/questions/40315451/proxy-requests-to-a-separate-backend-server-with-vue-cli?answertab=active#tab-top -
brenopolanski revised this gist
Sep 28, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -98,6 +98,7 @@ Use if u need "changeOrigin": true, "secure": false ``` **References**: - http://vuejs-templates.github.io/webpack/proxy.html -
brenopolanski revised this gist
Sep 28, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ Proxy requests using Webpack dev server to avoid cors in development mode. In your webpack.config file add: @@ -100,4 +98,8 @@ Use if u need "changeOrigin": true, "secure": false ``` **References**: - http://vuejs-templates.github.io/webpack/proxy.html - https://github.com/axios/axios/issues/853#issuecomment-374846375 - https://stackoverflow.com/questions/40315451/proxy-requests-to-a-separate-backend-server-with-vue-cli?answertab=active#tab-top -
brenopolanski revised this gist
Sep 28, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ **See**: http://vuejs-templates.github.io/webpack/proxy.html Proxy requests using Webpack dev server to avoid cors in development mode. In your webpack.config file add: -
brenopolanski created this gist
Sep 28, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,101 @@ Proxy requests using Webpack dev server to avoid cors in development mode. In your webpack.config file add: ``` "devServer":{ "proxy": { "/api": { "target": 'https://my-target.com', "pathRewrite": { '^/api': '' }, "changeOrigin": true, "secure": false } } } ``` The above example will proxy the request `axios.post(/api/posts/1 ... . . . .` to `https://my-target.com/posts/1` The above Git example, u need to change like this in your request: ``` axios.get('/api/a/threads.json', { headers: { // if u have some headers like this // 'Authorization': ' Basic //////some values' }, }).then(function (response) { console.log('response is : ' + response.data); }).catch(function (error) { if (error.response) { console.log(error.response.headers); } else if (error.request) { console.log(error.request); } else { console.log(error.message); } console.log(error.config); }); ``` In webpack.config file ........ ``` "devServer":{ "proxy": { "/api": { "target": 'https://a.4cdn.org', "pathRewrite": { '^/api': '' }, "changeOrigin": true, "secure": false } } } ``` the modified webpack config proxy will change your request like this.. ``` u can see this in chrome dev tool REQUEST HEADERS https://a.4cdn.org/a/threads.json ``` u can use multiple paths in devServer proxy like this In webpack.config file ........ ``` "devServer":{ "proxy": { "/api": { "target": 'https://a.4cdn.org', "pathRewrite": { '^/api': '' }, "changeOrigin": true, "secure": false }, "/login": { "target": 'https://github.com', // for example "pathRewrite": { '^/login': '' }, "changeOrigin": true, "secure": false }, "/post": { "target": 'https://facebook.com', // for example "pathRewrite": { '^/post': '' }, "changeOrigin": true } } } ``` Use if u need ``` "changeOrigin": true, "secure": false ```