Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 665
Yaroslav Avatar asked Jan 22 '26 01:01

Yaroslav


2 Answers

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

http-server --cors
like image 172
Yaroslav Avatar answered Jan 24 '26 17:01

Yaroslav


One of the possible solutions is simply serve package via npx

eg. npx serve ./folder -l 3003 --cors

The port can be dropped or specified

like image 28
serzn1 Avatar answered Jan 24 '26 19:01

serzn1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!