Comments (1)
ok, so digging into it more i think the pool is too much for the plugin, however there is a better way i found, just mention in the docs or also a code-check that getUpStream is not working with http2.
Then to make multiple different proxy-routes work with http2, you just use more server.registers AND the contraints magic which is built into fastify (the find-my-way lib)
so in my case i want to check the content-type, so made this contraints-strategy infastify:
const contentTypeMatchContraintStrategy = {
// strategy name for referencing in the route handler `constraints` options
name: 'contentType',
// storage factory for storing routes in the find-my-way route tree
storage: function () {
let handlers = {}
return {
get: (type: any) => { return handlers[type] || null },
set: (type: any, store: any) => { handlers[type] = store }
}
},
// function to get the value of the constraint from each incoming request
deriveConstraint: (req: any, ctx: any) => {
return req.headers['content-type']
},
// optional flag marking if handlers without constraints can match requests that have a value for this constraint
mustMatchWhenDerived: true,
// Bug not used no more
validate: (value: unknown) => {}
}
server.addConstraintStrategy(contentTypeMatchContraintStrategy);
And then you can use it for the proxy to check the different content-type's like so:
server.register(fastifyHttpProxy, {
http2: true,
upstream: "http://grpc-web-server",
httpMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'],
constraints: { "contentType":"application/grpc-web+proto" },
disableCache: true,
preHandler(req, reply, next) {
// Just for logging
console.log(`content-type match ${contentType}, forwarding to ${forwardUrl}`);
next();
}
});
server.register(fastifyHttpProxy, {
http2: true,
upstream: "http://grpc-server",
httpMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'],
constraints: { "contentType":"application/grpc+proto" },
disableCache: true,
preHandler(req, reply, next) {
// Just for logging
console.log(`content-type match ${contentType}, forwarding to ${forwardUrl}`);
next();
}
});
from fastify-http-proxy.
Related Issues (20)
- Integrate with fastify aws lambda HOT 3
- Is wildcard path matching supported? HOT 2
- Is custom error logging supported? HOT 2
- How to add caching capabilities HOT 5
- location headers is rewritten without the possibility to disable this behavior HOT 2
- The target websocket watch the specific url instead of upstream(host) with path HOT 7
- fail to proxy when starts with double slash HOT 4
- Unable to use http-proxy for all routes (/*) with @fastify/cors plugin HOT 4
- Provide a possibility to validate request payload before proxying the request HOT 2
- Crash when using with fastify-http-proxy websockets HOT 2
- `preHandler` option is incorrectly typed HOT 6
- Bug in rewrite prefix when having query params and url params in the URL HOT 3
- how to dynamic rewrite or change proxy url, changeOrigin or other options HOT 3
- Didn't get multipart/form-data value from proxy server to main server HOT 1
- Allow for dynamic websocket upstreams with `replyOptions.getUpstream` HOT 4
- Is it possible to use `preSerialization` or `onSend` hooks for fastify/http-proxy? HOT 4
- Header encoding error for custom response headers: Invalid character in header content ["custom-response-header"] HOT 3
- Allow overriding or modifying the queryString when proxying websockets HOT 2
- TypeError: Cannot read properties of null (reading 'server') HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-http-proxy.