lessquo
lessquo
Explore posts from servers
HHono
Created by lessquo on 6/20/2024 in #help
How to use custom fetch method for Hono client?
Okay thanks! I’ll share if I find any solution or workaround
6 replies
HHono
Created by lessquo on 6/20/2024 in #help
How to use custom fetch method for Hono client?
Got it! Well, short syntax is not really important. But I really want the interceptors feature. This is what I usually do with axios:
export const api = axios.create({ baseURL: import.meta.env.VITE_API_URL });

api.interceptors.request.use(async config => {
const idToken = await getIdToken();
if (idToken) {
config.headers.Authorization = `Bearer ${idToken}`;
}
return config;
});

api.interceptors.response.use(
response => {
if (['post', 'patch'].includes(response.config.method ?? '')) {
queryClient.refetchQueries({ type: 'active' });
}
return response;
},
error => {
if (error.response?.status === 401) {
signOut();
}
return Promise.reject(error);
},
);
export const api = axios.create({ baseURL: import.meta.env.VITE_API_URL });

api.interceptors.request.use(async config => {
const idToken = await getIdToken();
if (idToken) {
config.headers.Authorization = `Bearer ${idToken}`;
}
return config;
});

api.interceptors.response.use(
response => {
if (['post', 'patch'].includes(response.config.method ?? '')) {
queryClient.refetchQueries({ type: 'active' });
}
return response;
},
error => {
if (error.response?.status === 401) {
signOut();
}
return Promise.reject(error);
},
);
and here's my Hono client:
export const api = hc<ApiType>(import.meta.env.VITE_API_URL, {
headers: async () => ({ Authorization: `Bearer ${await getIdToken()}` }),
});
export const api = hc<ApiType>(import.meta.env.VITE_API_URL, {
headers: async () => ({ Authorization: `Bearer ${await getIdToken()}` }),
});
As you can see, Hono client can replace axios for the baseURL and headers, but not for the auto refetch and error handling. So, no way to achieve this currently?
6 replies
HHono
Created by ! Gaetan Puleo on 5/26/2024 in #help
Hot reload not working? (BUN)
Which bun version are you using?
7 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
Because I believe the RPC is one of the killer features of Hono. Everyone, including me, wants E2E type safety to reduce unnecessary duplicated code. Again, really appreciated
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I see. Maybe, it would be great to add this to the documentation in the Context or RPC page
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
not sure why export {} doesn't resolve my problem though. Thank you for your help
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
This looks cleaner
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
Or, I can just import the type file into the entry file: import './hono.d.ts';
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
You're right. Moving the type declaration part into index.ts file works too!
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I think I can create a reproducible project
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
Yes
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I guess, the difference is that I want to use the type from another package with RPC feature. I configured a monorepo:
my-app/
api
web
my-app/
api
web
package.json in the root directory:
{
"name": "my-app",
"private": true,
"workspaces": [
"api",
"web"
]
}
{
"name": "my-app",
"private": true,
"workspaces": [
"api",
"web"
]
}
The error happens when I try build command bun run build from the web project.
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
but this way, I have to add the type to all my route files
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
ofc I can do this as well:
import { Hono } from 'hono';
import { Variables } from '../hono';

export const users = new Hono<{ Variables: Variables }>().get('/me', c => c.json(c.var.me));
import { Hono } from 'hono';
import { Variables } from '../hono';

export const users = new Hono<{ Variables: Variables }>().get('/me', c => c.json(c.var.me));
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
If I remove the ContextVariableMap declaration, and remain const app = new Hono<{ Variables: Variables }>();, typescript can't recognize it.
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
import { User } from './schema';

// export type Variables = {
// me: User;
// };

declare module 'hono' {
// interface ContextVariableMap extends Variables {}
interface ContextVariableMap {
me: User;
}
}

export {};
import { User } from './schema';

// export type Variables = {
// me: User;
// };

declare module 'hono' {
// interface ContextVariableMap extends Variables {}
interface ContextVariableMap {
me: User;
}
}

export {};
The same error happens from the React project.
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I did with the updated one. I'll try your suggestion with the original code
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I don't understand your question. I'm totally new to Hono
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
No difference whether adding it or not. both works.
35 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I didn't and it works well?! don't know what the difference is
35 replies