the generated config/dev.exs file should read from PORT at compile time to set the endpoints port.
If we did this, people making a new Phoenix app could just run:
PORT=6000 mix phx.server to change the default port. As it is this doesn’t work cause the runtime file takes over. Unless someone has a better suggestion for how to acheive this?
OH man, yes! I was literally about the ask this yesterday then figured I must just be missing something so I’m going to try one more time to see what I’m doing wrong. But then I figured I would just stop my other running app so I could finish what I was doing first and once again completely forgot about it.
Adding a -p option to mix phx.server would also be an option (and more convenient for those of us who override our caps lock key ). I’m sure that must have come up some time in the past 10 years but I never read any of the discussion if it has. I’ve always thought it strange that there’s not a both obvious and super-convenient way to do this.
For dev, it shouldn’t be an issue since you can just restart the server, I think.
Personally, I think the environment variable should be called PHX_PORT since PORT is too generic. (I know it’s already there in config/runtime.exs, I’m just saying. Could be a “forwards compatibility” thing while keeping the legacy value.)
I’m guessing that the current behaviour is a hold-over from before Elixir/Phoenix had good support for runtime-based config. (I wasn’t around for that, but I understand that runtime config used to be an unsolved problem.)
Yeah I suspect the proper answer here is actually changing runtime.exs to pull the setting of the port out of the prod section, and then removing the port setup from dev.exs.