cloudflare / wrangler-legacy

🤠 Home to Wrangler v1 (deprecated)
https://workers.cloudflare.com
Apache License 2.0
3.2k stars 335 forks source link

wranger dev --host on localhost server #1955

Closed snakysnake closed 2 years ago

snakysnake commented 3 years ago

hey!

i would like to run wranger dev --host http://localhost:80

but when I try it gives me the following error message: Error: Protocol mismatch: protocol in --host and protocol in --upstream-protocol must match

would be amazing if one could just specify a local server and it works.

if there is an alternative solution for this please let me know, highly appreciated!

dear regards, snakysnake

jyn514 commented 3 years ago

@snakysnake you can already do this by specifying the upstream-protocol:

$ wrangler dev --host http://localhost http http
⚠️  --host provided, will run unauthenticated and upstream to provided host
unauthenticated
You have not provided your Cloudflare credentials.

Please run `wrangler login`, `wrangler config`, or visit
https://developers.cloudflare.com/workers/tooling/wrangler/configuration/#using-environment-variables
for info on authenticating with environment variables.
💁  Running preview without authentication.
👂  Listening on http://127.0.0.1:8787
💁  watching "./"
[2021-08-10 14:17:45] GET localhost/ HTTP/1.1 200 OK
[2021-08-10 14:17:45] GET localhost/favicon.ico HTTP/1.1 200 OK

The help message could be a little better though, since there's no --upstream-protocol option, it's a positional argument instead:

wrangler-dev 1.19.0
Start a local server for developing your worker

USAGE:
    wrangler dev [FLAGS] [OPTIONS] [ARGS]

FLAGS:
        --help       Prints help information
        --verbose    Toggle verbose output (when applicable)

OPTIONS:
    -c, --config <config>    Path to configuration file [default: wrangler.toml]
    -e, --env <env>          Environment to perform a command on
    -h, --host <host>        Host to forward requests to, defaults to the zone of project or to
                             tutorial.cloudflareworkers.com if unauthenticated
    -i, --ip <ip>            IP to listen on. Defaults to 127.0.0.1
    -p, --port <port>        Port to listen on. Defaults to 8787

ARGS:
    <local-protocol>       Sets the protocol on which the wrangler dev listens, by default this is http but can be
                           set to https
    <upstream-protocol>    Sets the protocol on which requests are sent to the host, by default this is https but
                           can be set to http
snakysnake commented 3 years ago

Thanks a lot, that somewhat helped! I now have another question... Maybe you can help me as well with this:

When trying to access some ressource on my local server via fetch inside of my worker, I get a 502 error where Cloudflare intercepts the connection (assumption) and tells me the following connect() blocked by restrictPeers()

I dont really know what it means and I can hardly find out anything when I google this issue, do you have any idea where I could look to find out how to fix this?

My setup is : a server hosted using xampp (localhost) where i activated everything i can to prevent cors issues, both in php as in apache, this is running on port 80

a wrangler instance which is running on port 8787, where i want the worker to fetch information from localhost:80

jyn514 commented 3 years ago

I'm not sure, sorry.

mchangrh commented 2 years ago

It seems that Cloudflare restricts certain IP ranges, including private IP ranges and some public ones (172.25.112.1) seems to be blocked as well. (Google NS)

threepointone commented 2 years ago

Closing since there's nothing actionable here.