-
Notifications
You must be signed in to change notification settings - Fork 464
Migrate server code to server/index.ts and simplify processes
#1066
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
Migrate server code to server/index.ts and simplify processes
#1066
Conversation
…structure, and streamline build and dev processes
…ion and documentation
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
kentcdodds
left a comment
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.
This is awesome! How is it done? I thought type stripping was only available without flags in node v25.
In any case, I absolutely love this if it works!
|
https://nodejs.org/en/learn/typescript/run-natively It was backported to Node 22 :) |
|
That's just fantastic. Thanks! |
|
@kasperpeulen I think introducing the middleware to the This code: // no ending slashes for SEO reasons
// https://github.com/epicweb-dev/epic-stack/discussions/108
app.get('*', (req, res, next) => {
if (req.path.endsWith('/') && req.path.length > 1) {
const query = req.url.slice(req.path.length)
const safepath = req.path.slice(0, -1).replace(/\/+/g, '/')
res.redirect(302, safepath + query)
} else {
next()
}
})It should be moved before the Perhaps other middleware should be moved too (I'm not sure)? |
|
Also, mocks are not loaded during |
|
Fixed here @davidesigner |
When reviewing the code, I noticed custom build stuff that seemed unnecessary. It made me feel that react-router needs a lot of boilerplate, and custom stuff build scripts.
I looked at the best practices in react router:
https://github.com/remix-run/react-router-templates/tree/main/node-custom-server
And I concluded that the epic-stack does custom things that are not necessary.
This gets rid of:
For running the server files with ts without compilation or tsx, node 22.18 is needed, so I updated that requirement.
They could also easily be js files, as they contain very little types. That is what is done in the react-router-templates, but running TS through node for those 2 files, seems complety valid to me in modern code.
Test Plan
build, dev, dev:no-mocks, start and start:mocks commands should still work the same way
I tested all of them manually.
Checklist
Screenshots