Custom server support for TanStack Start #3777
Replies: 3 comments 4 replies
-
I think this is needed. I want to use rust as a backend, so it'd be great to integrate with custom server. |
Beta Was this translation helpful? Give feedback.
-
This is also a requirement in our investigation for a nytimes.com framework replacement. A custom server is a must for enterprise sites. |
Beta Was this translation helpful? Give feedback.
-
I'm a little lost on what the next version will allow after DeVinxi and newer to me even kinda de-nitro, at least at runtime? Anyway, similar to op when going to probably adopt TSS some point after the current alpha is more stable and I find the time I'd love to incrementally migrate our currently Rakkas based app and having a custom router for this would be pretty helpful serving everything already migrated from tss and the rest from rakkas. While I wanted to share that I have this use-case as well I wanted to take this discussion as an opportunity to share some strategies I think are pretty elegant and flexible Inspired by RedwoodSDK docs export default defineApp([
// Middleware
function middleware({ request, ctx }) { /* Modify context */ },
function middleware({ request, ctx }) { /* Modify context */ },
// Request Handlers
route("/", function handler({ request, ctx }) {
return new Response("Hello, world!")
}),
route("/ping", function handler({ request, ctx }) {
return new Response("Pong!")
}),
handleFileRoutes(),
// if no file route matched continue
function middleware({ request, ctx }) {
// delegate to old app, NextJS, Rakkas, whatever
},
// or alternatively or maybe even in addition
async function middleware({ request, ctx }) {
const fileRoute = await handleFileRoutes();
const fileRouteResponse = await fileRouteResponse;
if (fileRouteResponse.status === 200)
return fileRouteResponse;
}
// delegate to old app like NextJS, Rakkas, whatever
},
]);
Also rwsdk addons are pretty cool which hook into the above example https://rwsdk.com/blog/full-stack-colocation And similar to Rakkas, Vike lets you define a custom server where you can do things and then let the app take over. Also what I really like about the new devinxi'd tss is not only server routes anywhere but even in the same file as an app route code example 👌 |
Beta Was this translation helpful? Give feedback.
-
I'm considering migrating a project from Next.js to TanStack Start, but I've hit a roadblock: I'm running Next.js behind an Express.js server for various middleware, which Next.js makes straightforward with their custom server feature. I don't see any analogous way to run TanStack Start within an existing Node.js process.
This may be a limitation of Vinxi, which can be started programatically but doesn't have any way to route calls to it programmatically AFAICT. Perhaps this feature could be added to the roadmap as a goal to achieve when moving away from Vinxi?
My use case may be a bit niche, but I imagine that being able to run behind Express.js would make gradual migration away from Next.js easier for lots of folks: You could have Express.js send requests for supported routes to TanStack Query and send all other requests to the old Next.js server as a fallback.
Beta Was this translation helpful? Give feedback.
All reactions