Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 fetch: How do I change the localhost port it calls?

I have a webpack-dev-server running with node.js on :8080 serving my frontend. I have a Spring Boot MVC application running on :8088 serving my actual backend service.

I have a login system I want to call on :8088, how would I change the permanent settings of the fetch function to refer to :8088 instead of :8080 every time the function is called?

I've tried the following, but to no avail:

login ({commit}, authData) {
      fetch('/api/login', {
        username: authData.username,
        password: authData.password
      }, {
        mode: 'no-cors',
        method: 'post',
        url: `http://localhost:8088`,
        credentials: 'include'
      }) // ... goes on 

However, it still refers to 8080:

bodyUsed: false
headers: Headers {  }
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://localhost:8080/api/login"
like image 740
cbll Avatar asked Nov 27 '17 10:11

cbll


1 Answers

Have you tried to put full url in your fetch first parameter? Pretty sure /api/login would make the request to the current host.

fetch('http://localhost:8088/api/login', {
    username: authData.username,
    password: authData.password
  }, {
    mode: 'no-cors',
    method: 'post',
    url: `http://localhost:8088`,
    credentials: 'include'
  })

Of course you need to have CORS enabled for this to work.

like image 172
Milad Avatar answered Sep 20 '22 22:09

Milad