Tengo un servidor Fastify que apunta a dos servidores Fastify "backend" y me gustaría generar un número aleatorio que luego se usa para decidir a qué backend enrutar.
Actualmente, solo funciona la primera vez y no puedo anular el flujo ascendente después.
server.register(require('fastify-http-proxy'), { upstream: '', replyOptions: { getUpstream: (originalReq, base) => { if (Math.random() < 0.5) { console.log(`setting base to backend1`) return `http://localhost:${backend1Port}` } else { console.log(`setting base to backend2`) return `http://localhost:${backend2Port}` } }, disableCache: true, cacheURLs: 0, }, })¿Cómo puedo hacer que, al actualizar, cambie el lugar al que se dirige?
Lo averigué. disabledCache debía estar fuera de las opciones de respuesta.
server.register(require('fastify-http-proxy'), { upstream: '', replyOptions: { getUpstream: (originalReq, base) => { if (Math.random() < 0.5) { console.log(`setting base to backend1`) return `http://localhost:${backend1Port}` } else { console.log(`setting base to backend2`) return `http://localhost:${backend2Port}` } }, disableCache: true, cacheURLs: 0, }, })