Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

prod-server.js

28 lines694 Bytes

1import express from 'express'
2import { toNodeHandler } from 'srvx/node'
3​
4const PORT = Number.parseInt(process.env.PORT || '3000')
5​
6const app = express()
7​
8const { default: handler } = await import('./dist/server/server.js')
9const nodeHandler = toNodeHandler(handler.fetch)
10​
11// Serve built client assets at /_ui/ prefix
12app.use('/_ui', express.static('dist/client'))
13​
14// All other requests go through the SSR handler
15app.use(async (req, res, next) => {
16 try {
17 await nodeHandler(req, res)
18 } catch (error) {
19 next(error)
20 }
21})
22​
23const httpServer = app.listen(PORT, (error) => {
24 if (error) {
25 throw error
26 }
27 console.log(`E2E app: http://localhost:${httpServer.address().port}`)
28})