-
Notifications
You must be signed in to change notification settings - Fork 94
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
Unable to use http-proxy for all routes (/*) with @fastify/cors plugin #309
Comments
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
hello @kovalenp |
@amitkTechno I didn't. You can remove |
I managed to fix this by adding the await server.register(proxyPlugin, {
prefix: "/api",
upstream: "http://localhost:3002",
}); However, this does mean that now your clients will have to access the proxied server over the |
This is still an issue. I just tried to create a Fastify web server in this fashion: const app = Fastify({
logger: true
});
// API routes
app.get('/api/stats', recordStats);
// CORS for API routes
await app.register(cors, {
prefix: '/api',
origin: '*'
});
app.register(proxy, {
upstream: 'http://localhost:3000', // remix server
prefix: '/',
rewritePrefix: '/',
http2: false
});
// Run the server!
await app.listen({ port: 3001 }); And it fails with the same error:
This is pretty basic stuff and it concerns me it doesn't work with Fastify. BTW I got around it by writing my own cors responder, rather than using @fastify/cors. |
Prerequisites
Fastify version
4.5.3
Plugin version
9.2.1
Node.js version
16.15.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.4
Description
I need to allow CORS for my Fastify application. To achieve this I'm using
@fastify/cors
package with following settings:if I register the http-proxy route for something like this:
I will get an error:
Probably because of this part of the lib:
Steps to Reproduce
Register
fastify/cors
withfastify/fastify-http-proxy
for all routesExpected Behavior
There is a way to enable cors on all routes for http-proxy plugin
PS:
I tried something like:
but it didn't do the trick for me
The text was updated successfully, but these errors were encountered: