CertifaiAI / classifai

:fire: One of the most comprehensive open-source data annotation platform.
https://classifai.ai/
Apache License 2.0
119 stars 25 forks source link

CORS Error, Port number did not reflected when change in build script #389

Open codenamewei opened 3 years ago

codenamewei commented 3 years ago

Describe the bug Port number in front end did not change when changed it in the build script

To Reproduce

  1. Download Classifai Repo
  2. Run
    Unix: ./startClassifai.sh --port=12222
    Windows: startClassifai.bat --port=12222
  3. In web browser, use inspect to see the URL endpoints called It can be seen that the url still maps back to 9999
Screenshot 2021-05-29 at 6 23 24 PM

Expected behavior Port of endpoints changed accordingly with build script when port number is specifically written.

Desktop (please complete the following information): Tested on Mac.

@amalsyahmi-certifai can you check if you are seeing the same scenario im facing, as of assignee to solve the bug, you can decide who to work on it

daniellim07 commented 3 years ago

@codenamewei Based on the screenshot, this should not be an issue on the web app. Build script would only change web app's port number (For instance, originally 4200 and you changed it to 12222).

The error message on CORS stated port 9999, has no relation to build script from web app. Note that port 9999 is coming from web app's production environment variable.

In summary, web app with port 12222 is talking to backend with port 9999. But backend does not enable CORS for port 12222, which means by default the backend would only allow same port to communicate with it, which does not involves CORS policy being violated.

The best way to overcome (for localhost situation) is to have CORS to whitelist with wildcard implementation, as you guys would keep changing the web app port.

codenamewei commented 3 years ago

@daniellim07 do you mean by doing wildcard search something like

router.route().handler(io.vertx.ext.web.handler.CorsHandler.create(".*.")

?

yeah we could not prevent people from the possibillity of changing port..

its very unlikely but possibly people by need to change port due to another application occupying the default port at the first place.

daniellim07 commented 3 years ago

@codenamewei Yes, but also need the following code like the ones I had provided back then in Slack channel. As CORS policy is very strict, any missing headers or method & etc will result in preventing backend from accepting request coming from web app.