T
TanStack8mo ago
rare-sapphire

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
yappiest-sapphire
yappiest-sapphire8mo ago
is this just for local dev usage?
rare-sapphire
rare-sapphireOP8mo ago
Also built
yappiest-sapphire
yappiest-sapphire8mo ago
you wouldnt use vite in prod anyhow
rare-sapphire
rare-sapphireOP8mo ago
yes
yappiest-sapphire
yappiest-sapphire8mo ago
so you need to configure your webserver correctly
rare-sapphire
rare-sapphireOP8mo ago
I don't have the vite plugin I am using the cli
yappiest-sapphire
yappiest-sapphire8mo ago
so that it always serves index.html
rare-sapphire
rare-sapphireOP8mo ago
Yup, i was wondering how do i get the routes without doing ti manually Can i use the cli?
yappiest-sapphire
yappiest-sapphire8mo ago
which cli
rare-sapphire
rare-sapphireOP8mo ago
"@tanstack/router-cli
yappiest-sapphire
yappiest-sapphire8mo ago
what for
rare-sapphire
rare-sapphireOP8mo 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
yappiest-sapphire
yappiest-sapphire8mo ago
are you really using bun in production to serve your app? or is this only on your local machine
rare-sapphire
rare-sapphireOP8mo ago
Yes Prod Can I parse the routeTree somehow?
yappiest-sapphire
yappiest-sapphire8mo ago
sounds super backwards to me you want your http server to always serve the index.html regardless which path is accessed
rare-sapphire
rare-sapphireOP8mo ago
yappiest-sapphire
yappiest-sapphire8mo ago
otherwise you cant handle not founds with router
rare-sapphire
rare-sapphireOP8mo ago
and in my index.html i point to a react file Literally what vite does

Did you find this page helpful?