Search code examples
macoscorshttpserver

enable CORS for local http server


I hosted my local files with http server. Just install on my Mac HTTP server with command:

npm install --global http-server

Then I start this server in needed directory with the command:

http-server

I had the CORS policy problem when trying to fetch my local HTML file from HTTP server response. It was blocked. Blocked by CORS policy


Solution

  • All I need to do for resolving this issue just to start HTTP server with cors option:

    http-server --cors