I want to run my project on localhost: 3000 / upct / ROUTES
But I have my API in: http://desarrollo.com/api
I want to use the proxy option in Webpack, but it does not work. I get a CORS error and others ... My proxy configuration looks like this:
CONFIG.devServer = { //host: 'localhost', port: 3000, proxy: { '/api/**': { target: 'http://desarrollo.com/api', secure: false, changeOrigin: true } }, contentBase: PATH.join(__dirname, '/src'), hot: true, inline: true, historyApiFallback: true/*, headers: { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin' : '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE' }*/ };
I execute my AJAX requests, for example:
$.ajax({ url: "http://desarrollo.com/api", data: "", type:"GET", dataType: "JSON", }) .done((respuesta) => { console.log(respuesta); }).fail(function(xhr, textStatus, errorThrown){ console.log("XHR: ", xhr, "Text Status: ", textStatus + '\n' + "Error Thrown: ", errorThrown); })
I supposse proxy is designed to execute AJAX requests in my API without CORS errors. But that does not work. What is wrong here?
Thanks.
reactjs webpack webpack-dev-server
JuMoGar
source share