How to enable cors in sonar server

Hi @tuanna2704,

This is not possible in SonarQube itself. The way you would set custom HTTP headers would be via a reverse proxy (note: we recommend using a reverse proxy to use HTTPS, so this could be part of that setup).

I see you’re running something on http://localhost:4200, so I’m guessing this is some sort of local development setup? Perhaps you could start some local NginX server, which would proxy to both ports (perhaps using subfolders?).

Something like:

             NginX (e.g.: http://localhost:8888)
                |                           |
             /myapp/                   /sonarqube/
                |                           |
App (http://localhost:4200)         SonarQube (http://localhost:9000)

That way, you can circumvent the CORS issue when running on localhost.

1 Like