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?
I have a noob question. I used to use the axios library and want a similar experience with the Hono client, such as shorter syntax, automatic JSON transformation and interceptors. Some suggest using ky instead of axios, but I don't know how to integrate it. The documentation (https://hono.dev/docs/guides/rpc#custom-fetch-method) is unclear to me. Could I get any guidance or example code?
6 replies
HHono
Created by lessquo on 5/19/2024 in #help
ContextVariableMap not recognized during build from other package in monorepo
I created src/hodo.d.ts file in my Hono project:
import { User } from './schema';

declare module 'hono' {
interface ContextVariableMap {
me: User;
}
}
import { User } from './schema';

declare module 'hono' {
interface ContextVariableMap {
me: User;
}
}
Then, the type was inferred out of the box:
import { Hono } from 'hono';

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

export const users = new Hono().get('/me', c => c.json(c.var.me));
And, I configured the RPC feature in my React project:
import { ApiType } from 'api/src';
import { hc } from 'hono/client';
import { getIdToken } from './firebase';

export const api = hc<ApiType>(import.meta.env.VITE_API_URL, {
headers: async () => ({ Authorization: `Bearer ${await getIdToken()}` }),
});
import { ApiType } from 'api/src';
import { hc } from 'hono/client';
import { getIdToken } from './firebase';

export const api = hc<ApiType>(import.meta.env.VITE_API_URL, {
headers: async () => ({ Authorization: `Bearer ${await getIdToken()}` }),
});
It worked like a charm. but then I tried build command and encountered an error:
$ tsc && vite build --mode dev
../api/src/routes/users.ts:3:56 - error TS2769: No overload matches this call.
Overload 1 of 2, '(object: JSONValue | {}, status?: StatusCode | undefined, headers?: HeaderRecord | undefined): Response & TypedResponse<never, StatusCode, "json">', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'JSONValue | {}'.
Overload 2 of 2, '(object: JSONValue | {}, init?: ResponseInit | undefined): Response & TypedResponse<never, StatusCode, "json">', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'JSONValue | {}'.

3 export const users = new Hono().get('/me', c => c.json(c.var.me));
$ tsc && vite build --mode dev
../api/src/routes/users.ts:3:56 - error TS2769: No overload matches this call.
Overload 1 of 2, '(object: JSONValue | {}, status?: StatusCode | undefined, headers?: HeaderRecord | undefined): Response & TypedResponse<never, StatusCode, "json">', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'JSONValue | {}'.
Overload 2 of 2, '(object: JSONValue | {}, init?: ResponseInit | undefined): Response & TypedResponse<never, StatusCode, "json">', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'JSONValue | {}'.

3 export const users = new Hono().get('/me', c => c.json(c.var.me));
Does ContextVariableMap type declaration not work with RPC feature?
35 replies
CDCloudflare Developers
Created by lessquo on 5/15/2024 in #pages-help
Error occurs accessing postgres with drizzle and postgres.js in Remix project
I've created a Remix project using create-cloudflare CLI as guided in https://developers.cloudflare.com/pages/framework-guides/deploy-a-remix-site/ and then I installed drizzle-orm and postgres, but I've got this error when I executed a simple select query:
Unexpected Server Error Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:
Unexpected Server Error Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:
The code:
export async function loader({ context }: LoaderFunctionArgs) {
const client = postgres(context.cloudflare.env.DATABASE_URL);
const db = drizzle(client);
const users = await db.select().from(userTable); // <- error here
return json({ users });
}
export async function loader({ context }: LoaderFunctionArgs) {
const client = postgres(context.cloudflare.env.DATABASE_URL);
const db = drizzle(client);
const users = await db.select().from(userTable); // <- error here
return json({ users });
}
This happens while running the app (remix vite:dev) locally.
3 replies
정산조회 결과는 정산이 완료된 것들만 보이나요?
정산조회로 가져온 Settlement 객체는 정산 및 계좌에 입금 완료된 것만 있나요? 아니면 정산지급일(paidOutDate) 이전에도 조회가 되나요?
14 replies
결제 취소 요청을 빠르게 연달아 보내면 FORBIDDEN_CONSECUTIVE_REQUEST 에러 발생
같은 paymentKey 에 대해 결제 취소 요청을 빠르게 연달아 보내면 FORBIDDEN_CONSECUTIVE_REQUEST 에러가 발생합니다. 예를들어 10,000원 결제건에 3,000원 취소, 7,000원 취소 요청을 거의 동시에 보내면 에러가 발생합니다. 혹시나 해서 멱등키를 사용해봤지만 결과는 같았습니다. 일단은 두 취소 요청 사이에 1초의 딜레이를 주었더니 정상적으로 처리되었는데요, 혹시 더 나은 해결 방법이 있을까요?
12 replies
Payment 객체는 외부로 노출되어도 문제 없나요?
Payment 객체를 그대로 DB 에 저장해서 사용하려는데 혹시 프론트엔드로 노출되면 안되는 민감한 정보가 포함되어 있는지 궁금합니다.
4 replies