Simple CORS workaround for local development
Keep is Simple
- tags
- javascript
- cors
- static_sites
Contents
I've been doing a lot of web development old school, just editing HTML
and JavaScript by hand without a build environment. Running npx
live-server
is an easy one liner to spin up a server, that opens a
browser for you and also updates changes on safe.
Sometimes that's not enough. Often you want to pull in data from an API, and that requires HTTPS, and also you need to work around CORS limitations. Here's a simple way to do that.
- First create a local certificate in
/tmp
if it's not there - Run
http-server
Option | Reason |
---|---|
--cors | Enable CORS via the Access-Control-Allow-Origin header |
-S | Enable https |
-P | Proxy unhandled requests to https://tezlabapp.com |
-c-1 | Turn off caching |
-C /tmp/cert.pem | Certificate file |
-K /tmp/key.pem | Key file |
Here's something you can stick in your path to run it.
|
|
Previously
Next