Giter Site home page Giter Site logo

Dynamic proxy target about koa-proxies HOT 3 CLOSED

vagusx avatar vagusx commented on August 13, 2024 3
Dynamic proxy target

from koa-proxies.

Comments (3)

wuliupo avatar wuliupo commented on August 13, 2024

Hello @feegloo,
I have a workaround, set different target in url path:

const Koa = require('koa');
const proxy = require('koa-proxies');
const app = new Koa();

const targets = {
    bar: 'http://localhost:3000/',
    baz: 'http://localhost:3001/'
};

app.use(proxy('/proxy/:target/', function(params) {
    return {
        target: targets[params.target] || 'http://localhost:8080',
        rewrite: p => p.replace(/^\/proxy\/\w+\//, '/'),
        changeOrigin: true,
        logs: true
    };
}));

app.listen(8080);

then we can call:

Refs: https://github.com/vagusX/koa-proxies/blob/master/index.js#L33
because the options can be a function.

from koa-proxies.

JanChvala avatar JanChvala commented on August 13, 2024

Hello @wuliupo, @feegloo,
in our case it is also not possible to distinguish the target by URL parameters.
For out local environment we use the referer header to route to either local server or remote server.

Simply passing the context to the mentioned function a1d3e19 allows to create dynamic target based on the context content.

I created pull request #52 for that.

from koa-proxies.

luxueyan avatar luxueyan commented on August 13, 2024

The issue is taking too long I have to fork and rewrite it for supporting router config https://github.com/luxueyan/koa-proxies

from koa-proxies.

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.