single-spa / single-spa-playground

A website that helps you set up single-spa
http://single-spa-playground.org
MIT License
39 stars 10 forks source link

Axios calls not working #44

Closed vivekksk closed 3 years ago

vivekksk commented 3 years ago

I am trying out single-spa and is stuck with the below issue

I have single spa running on port 5000 and 2 apps running on port 8081 and 8082. The apps were already running applications converted to single-spa. The apps have axios calls to get data from the server. After the migration, the Axios calls uses the URL http://localhost:5000/json/xxx.json where it should have been http://localhost:8081/json/xxx.json

How can I get this issue fixed? How can I make sure that each application calls its own backend and not single spa?

sample axios call

return new Promise((resolve, reject) => { axios.get('/json/xx.json', { responseType: 'json' }) .then((response) => { resolve(response.data) }) .catch(reject) .finally(() => { doSomething() }) })

joeldenning commented 3 years ago

Normally, api calls should be made relative to the current page, not relative to a microfrontend's url. However, if you'd like to make it relative to one microfrontend, you can use the webpack public path

axios.get(__webpack_public_path__ + '/json/xx.json')