Skip to content
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(client): Add hot reload for client packages #49

Draft
wants to merge 1 commit into
base: edge-civictechto
Choose a base branch
from

Conversation

Zen-cronic
Copy link
Collaborator

Fixes #47

{context: ['/api'],
target: 'http://127.0.0.1:5000/',
secure: false,
changeOrigin: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this config, the client-admin page can be accessed at localhost:3000. And all the api request will be proxied to http://127.0.0.1:5000/, where the server container is hosted.

But this error is thrown from the client-admin container:
[HPM] Error occurred while proxying request localhost:3000/api to http://127.0.0.1:5000/ [ECONNREFUSED]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it might be less obvious what's going on here to a future reader, perhaps leave the context for this in a comment?

Also, will this break things for future production builds?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to toggle this based on NODE_ENV? Although I'll admit that it's been helpful in the past to sometimes run a dev hot-reloading environment with NODE_ENV=production settings (minification, etc) 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, this won't affect static build, right? Ok, if so, maybe just a comment explaining why it's there inline :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i'll make sure to add some context! And yes, it's separate from the static builds. For now, I'm just trying to make it work.

@@ -22,4 +22,4 @@ RUN npm ci --production=false

COPY . .

CMD npm run build:prod
CMD npm start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one consideration is that this affects both dev and production builds, so we wont be able to publish container images that we eventually host from using this Dockerfile.

But since we're not publishing container images, maybe we can defer this. I'd recommend adding a TODO comment above to acknowledge the minor "regression" in making this change :)

But otherwise, I love this idea!

Suggested change
CMD npm start
# Starts dev environment
# TODO: Figure out how to implement Dockerfile(s) that works for both prod images and dev container.
CMD npm start

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i thought the prod deployments don't use this file as mentioned by the headline comment in this file:

# NOTE: This Dockerfile is not actually used by the docker-compose.yml.
# Instead, the file-server Dockerfile builds and serves these assets.
# But this file is still useful for development or deployments that do not use
# the docker compose configuration.

Maybe I understood it wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, you're right, that's worded a bit funny. Unless something has drastically changed (and I just did a cursory check that it hasn't) that's actually trying to warn ppl not to look for evidence or ability to serve the sub-apps in their dockerfiles. But the build process is still used, and the products of the build pulled into the file-server container (which ACTUALLY serves the content :) )

https://github.com/compdemocracy/polis/blob/c60752b2007578073ef788069fe7ba06fbe89c3f/file-server/Dockerfile#L102-L104

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, i'll go with your suggested change

@patcon
Copy link
Member

patcon commented Oct 21, 2024

Nice!

I'm realizing the bonus of submitting PRs upstream (at the same time) is that review there might allow us to benefit from the institutional knowledge of the build environment and its idiocyncrasies (often the product of lots of time spent learning and working around edge-cases)

cc: @NewJerseyStyle (bc i think this means our branching strategy still needs consideration 🙃 )

@NewJerseyStyle
Copy link
Member

Does this help? They have something for developers, may include hot reload?
https://gitlab.com/betabreak/polispilot/polis/-/blob/main/.devcontainer/README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add live code reloading for all client packages
3 participants