Skip to content

Conversation

@kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Dec 16, 2025

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:

  • The custom esbuild for the server files in other/build-server.ts
  • The custom dev-server in server/dev-server.js
  • The build:server command

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

  • Tests updated
  • Docs updated

Screenshots

Copilot AI review requested due to automatic review settings December 16, 2025 14:04
Copy link

Copilot AI left a 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.

Copy link
Member

@kentcdodds kentcdodds left a 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!

@kasperpeulen
Copy link
Contributor Author

https://nodejs.org/en/learn/typescript/run-natively

It was backported to Node 22 :)

@kentcdodds kentcdodds merged commit bac7bd4 into epicweb-dev:main Dec 17, 2025
12 checks passed
@kentcdodds
Copy link
Member

That's just fantastic. Thanks!

@davidesigner
Copy link

@kasperpeulen I think introducing the middleware to the server/index.ts file has caused a bug.

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 if (IS_DEV) that you added.

Perhaps other middleware should be moved too (I'm not sure)?

@davidesigner
Copy link

Also, mocks are not loaded during npm run dev... I think we should change for: "dev": "cross-env NODE_ENV=development MOCKS=true node index.ts",. What do you think about that?

@kasperpeulen
Copy link
Contributor Author

Fixed here @davidesigner
#1076

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.

3 participants