Giter Site home page Giter Site logo

Comments (1)

nickwinger avatar nickwinger commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.