mihaaai
mihaaai
Explore posts from servers
HHono
Created by mihaaai on 10/16/2024 in #help
Is there a way to get bindings outside the `c` Context of an inbound Request in Cloudflare Workers?
Got some updates, I did open a GH issue, for everyone landing here you can keep track of the progress here
10 replies
HHono
Created by mihaaai on 10/16/2024 in #help
Is there a way to get bindings outside the `c` Context of an inbound Request in Cloudflare Workers?
Unfortunatelly it won't work, the lib requires you to export an auth object from a auth.ts file to be able to run the CLI tool for migration against it, if I define the auth object within a middleware I can't export it and the CLI isn't able to find it. It also requires me to store another Variable in the context with c.set("auth", auth) besides the session and user already stored in the middleware example to be able to use the handler for the /api/auth/** routes becoming a strange antipattern.
10 replies
HHono
Created by mihaaai on 10/16/2024 in #help
Is there a way to get bindings outside the `c` Context of an inbound Request in Cloudflare Workers?
Mmm, not sure this is an optimal way, only imports of betterAuth and Kysely are about half MB of bundle size, again not sure if this is a heavy lift to the whole app, since being it a middleware will execute the setup each time a request comes in, also this lib has handy methods to manage state for Hono, but no reference of D1 Binding within Hono
10 replies
HHono
Created by mihaaai on 10/16/2024 in #help
Is there a way to get bindings outside the `c` Context of an inbound Request in Cloudflare Workers?
No luck, no matter what I try seems impossible to get a reference of the BIndings, even with the docs about contextStorage() it crashes the app on runtime with service core:user:app: Uncaught Error: Context is not available
10 replies
SSolidJS
Created by mihaaai on 9/2/2024 in #support
How to trigger server function for SSR when transitioning routes?
Thanks for the help, indeed using the slug as an argument to getInitialProps solved the problem, not everything works as expected! I've been reading about not using the use* functions on the server but damn, the docs are so much empty... Kudos! 🙏
7 replies
SSolidJS
Created by mihaaai on 9/2/2024 in #support
How to trigger server function for SSR when transitioning routes?
NavigatorItem.tsx This is one of the navigation components that is mounted right inside the <Router> but not inside the [slug].tsx page
import { useNavigate } from "@solidjs/router";

const NavigatorItem = () => {
const navigate = useNavigate();
return <div onClick={() => navigate("/path/to/another-slug", { replace: true })}>...</div>
}
import { useNavigate } from "@solidjs/router";

const NavigatorItem = () => {
const navigate = useNavigate();
return <div onClick={() => navigate("/path/to/another-slug", { replace: true })}>...</div>
}
app.tsx The Root:
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { MetaProvider, Title } from "@solidjs/meta";
import { Suspense } from "solid-js";

import NavigatorItem from "~/components/Header/NavigatorItem";
import "./app.css";

const App = () => {
return (
<Router
root={(props) => (
<MetaProvider>
<Title>App</Title>

<NavigatorItem />
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
};

export default App;
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { MetaProvider, Title } from "@solidjs/meta";
import { Suspense } from "solid-js";

import NavigatorItem from "~/components/Header/NavigatorItem";
import "./app.css";

const App = () => {
return (
<Router
root={(props) => (
<MetaProvider>
<Title>App</Title>

<NavigatorItem />
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
};

export default App;
The problem is that getInitialProps() gets triggered only on full refresh or first load, if I click on <NavigatorItem /> the route changes but the content isn't fetched for the new slug
7 replies
SSolidJS
Created by mihaaai on 9/2/2024 in #support
How to trigger server function for SSR when transitioning routes?
Sure: /path/to/[slug].tsx This is the page itself
import { cache, useParams } from "@solidjs/router";
import { getApiEndpoint } from "~/lib/websocket";

export const getInitialProps = cache(async () => {
"use server";
const params = useParams();
// make call to backend with params.slug
const res = await apiService.fetch(url);
const info = await res.json();

if (res.status === 200) return info;
return {};
}, "slug");

// Adding this or not doesn't make difference
export const route = {
load: () => getInitialProps(),
};

const Slug = () => {
const info = createAsync(async () => await getInitialProps());
return <div>{info().user}</div>
}

export default Slug
import { cache, useParams } from "@solidjs/router";
import { getApiEndpoint } from "~/lib/websocket";

export const getInitialProps = cache(async () => {
"use server";
const params = useParams();
// make call to backend with params.slug
const res = await apiService.fetch(url);
const info = await res.json();

if (res.status === 200) return info;
return {};
}, "slug");

// Adding this or not doesn't make difference
export const route = {
load: () => getInitialProps(),
};

const Slug = () => {
const info = createAsync(async () => await getInitialProps());
return <div>{info().user}</div>
}

export default Slug
7 replies