1

Doing a javascript only assignment, i was provided an ubuntu machine and would like to spin up a container with a nodejs Serving the HTML, css, javascript. Then i would like another container with the backend API...since this all happening in the same server or IP , Is that posible no cross Origin calls????

2 Answers 2

4

See the Same-origin policy:

Two URLs have the same origin if the protocol, port (if specified), and host are the same for both.

You can't have two different services listening on the same port, so even if your static content and API servers shared an IP address, they would have to run on different ports.

So you would either need to configure CORS for the API server, or configure your static content server to proxy requests to the API server.

2
  • So if I specificied and allow CORS in the server, that would suffice?...that could work because only my front-end is not allowed libraries, framework, etc
    – user998548
    Apr 27, 2019 at 23:46
  • @user998548 — yes
    – Quentin
    Apr 28, 2019 at 7:04
2

You would need to provide the correct CORS settings on your backend API; CORS does take into account port numbers. See this post for reference: CORS error on same domain?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.