How to allow customs hosts in development mode

AI-generated summary

The discussion revolves around allowing custom hosts in a Discourse development environment. mompo encountered a “Blocked host” error when trying to access their instance via hostname, and was advised to add the hostname to the config.hosts environment configuration.

Osama suggested setting the DISCOURSE_DEV_HOSTS environment variable by prepending it to the command that starts the unicorn server or by adding it to the shell’s rc file. However, Stanzilla reported that this did not work when using Docker for development.

Osama clarified that the environment variable needs to be set inside the Docker container, and provided an example using d/boot_dev to set the variable. However, Stanzilla reported a “502 Bad Gateway” error after trying this solution.

Hi.

I’m new to discourse and started diving into it by setting up a development system, following this howto.
Afterwards I was able to access my instance via ip address, but trying to access via hostname fails with following message:

Blocked host: discourse_example_net
To allow requests to discourse_example_net, add the following to your environment configuration:
config.hosts << “discourse_example_net”

I found this PR, but I don’t know how to set the env var.

Best,
Luis

You can prepend DISCOURSE_DEV_HOSTS=discourse_example_net to the command that starts the unicorn server, or you can set the variable in your ~/.bashrc (or the rc file of the shell you use).

I tried DISCOURSE_DEV_HOSTS=xxx.ngrok.io d/unicorn and it did not work, sadly

I’m assuming you mean by “did not work” you still got the same error as the OP? It looks like you’re using docker for development, so you need to set this environment variable inside the container, not the host machine. I don’t use docker for development, but it looks like d/boot_dev can set variables inside the container for you:

d/boot_dev -e DISCOURSE_DEV_HOSTS=xxx.ngrok.io

And then run d/unicorn.

That always ends up in

502 Bad Gateway
The server returned an invalid or incomplete response.