-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat(create-pages): api handling #1108
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
review on the types.
|
||
export type CreateApi = <Path extends string>(params: { | ||
path: Path; | ||
render: 'static' | 'dynamic'; |
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'm not sure if we call render
for api.
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.
changed to mode
for now... let me know what you think
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'm neutral. @sandren may have an idea.
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. |
path, | ||
typeof window !== 'undefined' | ||
? window.location.href | ||
: 'http://localhost', // FIXME what should this be? |
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.
@dai-shi do you know how this should be handled? Request
needs a valid url, which seems to require a host. When we run the tests localhost
is the "host".
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 think having always localhost
is okay. When we learn more use cases, we can reconsider. As a workaround, we could use unstable_getHeaders
for "host".
new URL(path, 'http://localhost')
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.
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.
Hmm, I'm not sure why it errors. let's look into it separately.
Actually, you can probably read "host" header from params.headers, but if it's not available, we can fallback to localhost
.
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.
like this?
const req = new Request(
new URL(path, options.headers['host'] ?? 'http://localhost'),
options,
);
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'm not sure but should we need the protocol part too?
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.
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.
Yes, I mean the same and options.headers['host']
doesn't include the protocol part, right?
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.
Good point about the protocol.
However, handApi will run on our server, right?
So will we always want to request to http://localhost actually? I think it makes sense to remove the use of the host header since we expect this to request from the server this code executes on.
Correct me if I'm off here though.
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 runs on our server (dynamic) or the build time (static).
I could imagine some use cases would check "host" and change the behavior based on it. So, at least they should be able to read the "host" header.
At that point, creating URL
with the "host" header makes sense, but we can defer the decision until we see clear requirements.
1621a2f
to
f2660af
Compare
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.
LGTM
@@ -147,6 +147,15 @@ export type CreateLayout = <Path extends string>( | |||
}, | |||
) => void; | |||
|
|||
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'; |
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 don't mind, but any reason for this choice?
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 was hoping just to make this typesafe, but happy to add more methods or remove it if it gets in the way
This adds api route handling in createPages with tests