-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
fix: handleApi and related issues (with example defineRouter with api call) #1116
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
return { | ||
headers: {}, | ||
status: 200, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, this looks valid and I expect it returns an empty content. Not sure where it returns an html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just when body is undefined or null 👀 - I can look into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a place where we can set the body in the middleware, but not sure if that is the right place to fix this or not. Let me know what you think of the change and where may be better to fix it if that's the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
body
is optional, so you don't need to set it. Or, I misunderstand your question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change in the middleware handler: https://github.com/dai-shi/waku/pull/1116/files#diff-4142accf18d84717732f9aa0ed86505383a968a3369c6049dea5c620454322e0L157-L160
is to fix the issue in the description: #1116 (comment)
the e2e tests confirm that it is the wrong fix, but I think there is a case where we should return an empty body from the server and instead we send html still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a wrong fix. It's not the handler job to create the body. Maybe, I misunderstand the hono behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if c.body(null)
is causing the problem?
waku/packages/waku/src/lib/hono/engine.ts
Line 64 in 52f7ad6
return c.body(null, status as never, headers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't this^.
Somehow the middleware handler is setting the body
to a readablestream (it should just not be defined on the ctx object I think), but I can't see where it is making the change yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking into it. it looks like it's vite behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, there were various bugs, most of which are my bad.
the problem was that we fallback to an html page when no api body is set we can set one here, but I'd like to ask what the proper way to fix this is
{ | ||
path: [ | ||
{ type: 'literal', name: 'api' }, | ||
{ type: 'literal', name: 'hi.txt' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension is necessary, if isStatic=true
. Otherwise, unnecessary, I think.
const willBeHandled = async (pathname: string) => { | ||
if (pathname.startsWith('/@')) { | ||
return true; | ||
} | ||
const vite = await vitePromise; | ||
try { | ||
const result = await vite.transformRequest(pathname); | ||
return !!result; | ||
return !!result?.map; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels too hacky. If anyone has any idea, it would be appreciated.
As it turns out, there were several issues and fixed! |
@dai-shi when I curl
http://localhost:3000/api/hi
I see the log, but the response is still html.Am I setting this up wrong, or is there more work to do so that we response with 'Hello World' here?