-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Middleware / ignore routes to be server by one when bundled with server #329
Comments
For now it's a bit awkward, In dev you'd make a custom Vite plugin, see What we need is a middleware feature. I think a Granted we do have loaders which can act as middleware essentially, they do receive the request and can throw or return Response, though we need better testing/docs around that still. There's also some trade-offs, so we'd need to think over it. |
You could run your rust server on top of the One server for now too. |
One of my main goal is to have the app be a single binary with rust for speed on the server and rich SPA app for the web and iOS mobile app so bundling the one server would defeat the purpose. Right now I'm setting the one({
web: {
defaultRenderMode: 'spa',
redirects: [],
ignoreRoutes: ['/signout', /^api/],
}); The way I usually have done in the past is I have rust server handle all the routes and not found routes goes to the SPA app that is done by the rust proxy middleware. In prod it just always returns the index.html so I don't need another server for the client. |
Hm ok that makes sense.
Not sure what you mean / what ignoreRoutes does? If you have your own Rust server you can ignore routes there right. |
Here is a minimal repo.
import { Image } from "@tamagui/image-next";
import { Text, YStack } from "tamagui";
import { ToggleThemeButton } from "~/interface/ToggleThemeButton";
import oneBall from "../public/app-icon.png";
import { useEffect } from "react";
const makeApiRequest = async () => {
try {
const res = await fetch("/api/hello").then((res) => res.json());
console.log(res);
} catch (e) {
console.error(e);
}
};
export function HomePage() {
useEffect(() => {
makeApiRequest();
}, []);
return (
<YStack bg="$color1" mih="100%" gap="$4" ai="center" jc="center" f={1}>
<Text fontSize={20}>Hello, world</Text>
<Image src={oneBall} width={128} height={128} />
<ToggleThemeButton />
</YStack>
);
}
import { Hono } from "hono";
import { serve } from "bun";
const app = new Hono();
// API routes
app.all("/api/*", (c) => c.json({ ok: true }));
// SPA proxy
app.all("*", async (c) => {
return await fetch("http://localhost:8081" + c.req.path);
});
serve({
fetch: app.fetch,
port: 3000,
}); Run Now go to the server folder and run the server via |
I'm bundling the one app with a rust server so a single binary serves both the rust server routes and the one spa app. There are some urls that I need one to ignore so GET on those routes would got to the server instead.
Is there something like
navigateFallbackDenyList
in one similar to the one that VitePWA supports?https://vite-pwa-org.netlify.app/workbox/generate-sw#exclude-routes
The text was updated successfully, but these errors were encountered: