-
Notifications
You must be signed in to change notification settings - Fork 26
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: Add fastify-cors example #444
feat: Add fastify-cors example #444
Conversation
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.
Thank you for the contribution, @akinorimizushima!
We have been discussing how we can make setting up CORS a bit easier. The PR connectrpc/connect-es#526 adds a nice little helper for that. Do you mind waiting for that PR to land so you can use it here?
node.js/fastify-cors/server.ts
Outdated
const server = fastify() | ||
|
||
await server.register(cors, { | ||
origin: "*", |
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 should be origin: true
, but with a comment that this is only recommended for development, not for production. Please take a the @fastify-cors documentation.
node.js/fastify-cors/server.ts
Outdated
allowedHeaders: [ | ||
"content-type", | ||
"Connect-Protocol-Version", | ||
"Access-Control-Allow-Origin", | ||
], |
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.
We need a couple more headers here, and we also need to set exposedHeaders
and methods
.
But with connectrpc/connect-es#526, you can simply use the values we export.
Hi @timostamm, thanks for heads up. Okay, will work on it once the feature is published. |
325cae3
to
df8263f
Compare
@timostamm Pushed some commits using the upgraded version but #463 is doing the similar thing. So feel free to reject it if this PR is not helpful as an example. |
Hey @akinorimizushima. This is definitely a helpful example. What we are trying to do is make each example (express, fastify, etc.) self-sufficient and showing both a full-stack as well as a CORS example. #463 is an attempt to unify the Express project so that we don't have |
Hi @akinorimizushima. On second thought, we decided to combine these changes into #463 since that PR was already doing a massive refactoring of the Node examples. Your work on |
This PR refactors the Connect for Node.js examples. The major changes are: - The examples in the `/node.js` directory have all been moved to the top-level along with the other projects. - Each Node example now contains a full CORS setup so that the project can be run with a separate web interface using CORS. - In addition, the examples also server the frontend interface via Node, so they can be accessed from a web browser without the need for CORS. Thanks to @akinorimizushima and his work on #444, which inspired this CORS refactoring. The `fastify` example in #444 has been ported to this PR.
This will add an example using fastify-cors which can receive requests from different hosts or ports.