Skip to content
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

Merged
merged 10 commits into from
Jan 6, 2025

Conversation

tylersayshi
Copy link
Contributor

@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?

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
waku ⬜️ Ignored (Inspect) Visit Preview Jan 6, 2025 11:35pm

Copy link

codesandbox-ci bot commented Jan 2, 2025

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.

Comment on lines 211 to 214
return {
headers: {},
status: 200,
};
Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Owner

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?

return c.body(null, status as never, headers);

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Owner

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.

tylersayshi and others added 6 commits January 5, 2025 13:00
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' },
Copy link
Owner

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.

Comment on lines 205 to 212
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;
Copy link
Owner

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.

@dai-shi
Copy link
Owner

dai-shi commented Jan 6, 2025

As it turns out, there were several issues and fixed!

@dai-shi dai-shi changed the title chore: example defineRouter with api call fix: handleApi and related issues (with example defineRouter with api call) Jan 6, 2025
@dai-shi dai-shi marked this pull request as ready for review January 6, 2025 23:41
@dai-shi dai-shi merged commit 4ce83b2 into dai-shi:main Jan 6, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants