T
TanStack11mo ago
extended-salmon

Redirect routing to correct route from bun

I am using the new bun 1.2 to bundle my SPA and so far everything is working great! I only have a small issue which I am sure as been addressed before but I couldn't find. Basically with the new bun 1.2 it allows you bundle the app without the need of vite here's the code
import app from "./public/app.html";

Bun.serve({
static: {
"/": app,
});
import app from "./public/app.html";

Bun.serve({
static: {
"/": app,
});
now the thing is i have two routes / and /login. When I navigate to /login with the link component from the router it works fine as I would expect it to, but when I land to localhost:3000/login obviously it doesn't work as it's not bundling the app there. Any suggestions on where I can read more / find a possible solution to this?
18 Replies
eastern-cyan
eastern-cyan11mo ago
is this just for local dev usage?
extended-salmon
extended-salmonOP11mo ago
Also built
eastern-cyan
eastern-cyan11mo ago
you wouldnt use vite in prod anyhow
extended-salmon
extended-salmonOP11mo ago
yes
eastern-cyan
eastern-cyan11mo ago
so you need to configure your webserver correctly
extended-salmon
extended-salmonOP11mo ago
I don't have the vite plugin I am using the cli
eastern-cyan
eastern-cyan11mo ago
so that it always serves index.html
extended-salmon
extended-salmonOP11mo ago
Yup, i was wondering how do i get the routes without doing ti manually Can i use the cli?
eastern-cyan
eastern-cyan11mo ago
which cli
extended-salmon
extended-salmonOP11mo ago
"@tanstack/router-cli
eastern-cyan
eastern-cyan11mo ago
what for
extended-salmon
extended-salmonOP11mo ago
to add automatically to the static all the routes of the spa
Bun.serve({
static: {
"/": app,
"/login": app,
})
Bun.serve({
static: {
"/": app,
"/login": app,
})
like this works
eastern-cyan
eastern-cyan11mo ago
are you really using bun in production to serve your app? or is this only on your local machine
extended-salmon
extended-salmonOP11mo ago
Yes Prod Can I parse the routeTree somehow?
eastern-cyan
eastern-cyan11mo ago
sounds super backwards to me you want your http server to always serve the index.html regardless which path is accessed
extended-salmon
extended-salmonOP11mo ago
eastern-cyan
eastern-cyan11mo ago
otherwise you cant handle not founds with router
extended-salmon
extended-salmonOP11mo ago
and in my index.html i point to a react file Literally what vite does

Did you find this page helpful?