-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): Enable host
option for yarn rw serve
#8385
Conversation
host
option for yarn rw serve
Just to confirm that this fix will work for you, @dennemark are you running the api-server independently of the CLI? We should probably make this change anyway just to be consistent, but if you are, the work here won't solve the bug for you, which I think you could've only really experienced by running the api-server binary as-is and not through the CLI Update: the api-server CLI handlers are also for |
won't make much of a difference for getPaths but getConfig isn't memoized so that one is a little excessive to keep calling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @Josh-Walker-GM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably okay'ed a bit too early; I should test a few more things because there's a lot of entry points here
yarn rw serve
yarn rw dev
- running api-server's bins (
rw-api-server-watch
,rw-server
) independently of the CLI- it's unlikely that
rw-api-server-watch
is used independently of the CLI
- it's unlikely that
- passing flags via CLI
- setting config in
redwood.toml
yarn rw dev
Flag | n/a |
Toml | api settings are respected |
Now if you set host
in the api table in redwood.toml
:
[api]
port = 8911
+ host = "0.0.0.0" # normally 'localhost'
yarn rw dev
doesn't work out of the box. Before it did, but only because host was ignored, which could also be considered a bug.
To get it working again, you have to set RWJS_DEV_API_URL
(an env var that has no TOML-equivalent nor is it used anywhere else) to "http://0.0.0.0"
so that the webpack dev server proxy works again:
target: `${process.env.RWJS_DEV_API_URL ?? 'http://localhost'}:${port}`, |
Again, I'm not saying this is a bug or is undesirable. It's just different than it was before.
Here's an old one this is related to: #6362 |
So much progress while I was asleep... thanks so much! Within my development environment I do not need @redwoodjs/api-server. But when I try to run my docker container, I need to install @redwoodjs/api-server and @redwoodjs/internals seperately. (I am not fully sure why, anymore, since those packages should be installed anyways). But when starting the docker container, I am calling
Btw. right now I have set |
@dennemark I think I've got my head wrapped around all the changes here now. Here's the state of things: With this PR, if you run the web and api servers separately, the settings for each will be respected. But if you run them together, since we only start one fastify server at the moment, the web settings will be used. You said you were running I'll merge this and release an RC; if you could upgrade to it (I'll follow up with the version once it's published) and confirm that it works the way you expect that'd be greatly appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Josh-Walker-GM, and thanks for letting me hijack this one.
I want to follow up on a few more discussions with others, but want to get an RC out for testing.
* Add 'host' option which defaults to toml value - which defaults to 'localhost' * Update api-server cli-handlers too * style: save project config calls in var won't make much of a difference for getPaths but getConfig isn't memoized so that one is a little excessive to keep calling * style: save project-config calls where possible * style: prefer ?? to || for undefined values * style changes * enable api-server to take flag * remove stray nullish accessor * style: remove needless instantiation * use existing config in scope * style * set host in dev handler * remove needless null checks * style: make api command more readable * add host to watch * get dev test passing * get serve test passing * c * get watch working * remove console log * comments * style * fix dev handler when web host is set * revert to expected webpack behavior * fix test --------- Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
* Add 'host' option which defaults to toml value - which defaults to 'localhost' * Update api-server cli-handlers too * style: save project config calls in var won't make much of a difference for getPaths but getConfig isn't memoized so that one is a little excessive to keep calling * style: save project-config calls where possible * style: prefer ?? to || for undefined values * style changes * enable api-server to take flag * remove stray nullish accessor * style: remove needless instantiation * use existing config in scope * style * set host in dev handler * remove needless null checks * style: make api command more readable * add host to watch * get dev test passing * get serve test passing * c * get watch working * remove console log * comments * style * fix dev handler when web host is set * revert to expected webpack behavior * fix test --------- Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
@dennemark I just released this PR in an RC: |
@dennemark another update: I've changed my by plan here. I'm going to revert #8019 and release a patch till we've got this sorted out in main and know all the edge cases. So this PR won't be available in the patch when I actually release it. Sorry for the churn! I'll follow up one more time when v5.2.3 is released |
Thanks so much for the effort! So i am going to test it in one of the follow up releases? Going to check the commits tomorrow. Curious, why this issue is quite complex :) |
@dennemark yeah you can ignore the RC I mentioned earlier and use this patch instead https://github.com/redwoodjs/redwood/releases/tag/v5.2.3. This patch just reverts #8019, so you don't have to set The reason for complexity here is 1) there's a lot of different deploy environments and 2) there's a lot of different combinations to these settings among the CLI commands, and checking them all just takes time. (And I have other things I'm supposed to be working on instead, so I kind of need this one wrapped for the time being.) |
Thanks for the heads up and your effort :) |
Problem
We need to have some consistent way to set the host used when running
yarn rw serve [side]
and we also want to default tolocalhost
.See #8019 (comment)
Solution
We add a
--host
option to theyarn rw serve
command. It defaults to the value inside the appropriateredwood.toml
option. These toml options themselves default tolocalhost
when not explicitly defined.We should also be aware that when we run both sides using
yarn rw serve
we preferentially choose theweb
config over theapi
config. We have this because we offer both options but only start one fastify server when running both sides.