Configure ngrok's CORS headers

Solution 1:

I just stumbled across this issue today and was able to resolve it by starting ngrok and including the -host-header flag.

ngrok http -host-header=rewrite 3000

From the docs:

Use the -host-header switch to rewrite incoming HTTP requests.

If rewrite is specified, the Host header will be rewritten to match the hostname portion of the forwarding address.

Solution 2:

First of all ngrok is just a tunnel and not a server so configuring CORS header in ngrok is not at all possible. So any kind of CORS configuration needs to be done at the server level.

For example if you are using a nginx server, you need to configure header in the nginx conf file like:

location / {
    /*some default configuration here*/
    add_header 'Access-Control-Allow-Origin' '*';
}

By adding this header, you say that cross origin access to your address is allowed from any address as the value of the header is '*'. You can also specify a particular address for which the access to your address is allowed by replacing the value.