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

Use separate server.dev.js and server.prod.js files #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vcarl
Copy link

@vcarl vcarl commented Dec 28, 2024

I used this template as a reference while migrating a Discord bot + Remix v2 app to RRv7, and ran into a couple of odditites because of the assumptions made in this project. I found the single dev/prod entrypoint with dynamic imports impossible to set up with a complex TypeScript project. The way the production server script isn't included in any other part of the build made it tricky to get a daemon up with an appropriate execution context.

This splits apart server.js into server.dev.js/server.prod.js, shifts the app.listen() call into both files, and sets up HMR/static file hosting as necessary in each environment. I found this allowed me to use a .js file at the root of the project, copied into the Docker build, while still starting up all the important functionality in server/app.ts. I think this is likely to be a clearer starting point for others in a similar situation.

I'm not sure if this is precisely equivalent to the previous implementation, which imported the module for server/app.ts within a middleware function on each request. That seemed possibly undesirable (but I'm not sure if it was intended to enable o11y etc).

I used this template as a reference while migrating a Discord bot + Remix v2 app to RRv7, and ran into a couple of odditites because of the assumptions made in this project. I found the single dev/prod entrypoint with dynamic imports impossible to set up with a complex TypeScript project. The way the production server script isn't included in any other part of the build made it tricky to get a daemon up with an appropriate execution context.

This splits apart `server.js` into `server.dev.js`/`server.prod.js`, shifts the `app.listen()` call into both files, and sets up HMR/static file hosting as necessary in each environment. I found this allowed me to use a `.js` file at the root of the project, copied into the Docker build, while still starting up all the important functionality in `server/app.ts`. I think this is likely to be a clearer starting point for others in a similar situation.

I'm not sure if this is precisely equivalent to the previous implementation, which imported the module for `server/app.ts` within a middleware function on each request. That seemed possibly undesirable (but I'm not sure if it was intended to enable o11y etc).
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.

1 participant