Code Monkey home page Code Monkey logo

Comments (5)

alombarte avatar alombarte commented on June 2, 2024

Hi @fabubacker ,

This is supported out of the box in the Enterprise edition: https://www.krakend.io/docs/enterprise/service-settings/virtual-hosts/ but not in the community.

You can make conditional requests with CEL in CE, but you should have multiple backends, not endpoints. You cannot create an endpoint twice.

You can also use Lua scripts and Go pugins to support this scenario, there are plenty of options

from krakend-ce.

fabubacker avatar fabubacker commented on June 2, 2024

Thanks @alombarte for the response. With CEL and multiple backends, how to differentiate the request between backends with two different domain names? Is it possible in community edition without any customization like Lua scripts and Go pugins? The apps we are looking to onboard in api gateway are simple ones so not looking to making it as complex with custom scripts.

from krakend-ce.

alombarte avatar alombarte commented on June 2, 2024

Hi @fabubacker ,

The following configuration does precisely what you want; it's functional (uses KrakenD itself as backend), so you get the point.

{
    "version": 3,
    "$schema": "https://www.krakend.io/schema/krakend.json",
    "host": [
        "http://localhost:8080"
    ],
    "echo_endpoint": true,
    "endpoints": [
        {
            "endpoint": "/all-domains",
            "backend": [
                {
                    "url_pattern": "/__echo/domain-A",
                    "allow": [
                        "req_uri"
                    ],
                    "group": "A"
                },
                {
                    "url_pattern": "/__echo/domain-B",
                    "allow": [
                        "req_uri"
                    ],
                    "group": "B"
                }
            ]
        },
        {
            "endpoint": "/one-domain",
            "backend": [
                {
                    "url_pattern": "/__echo/domain-A",
                    "allow": [
                        "req_uri"
                    ],
                    "group": "A",
                    "extra_config": {
                        "validation/cel": [
                            {
                                "check_expr": "'a.com' in req_headers['X-Forwarded-Host']"
                            }
                        ]
                    }
                },
                {
                    "url_pattern": "/__echo/domain-B",
                    "allow": [
                        "req_uri"
                    ],
                    "group": "B",
                    "extra_config": {
                        "validation/cel": [
                            {
                                "check_expr": "'b.com' in req_headers['X-Forwarded-Host']"
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

Then try the following commands:

curl -H'Host: z.com' http://localhost:8080/all-domains
curl -H'Host: a.com' http://localhost:8080/one-domain
curl -H'Host: b.com' http://localhost:8080/one-domain

from krakend-ce.

fabubacker avatar fabubacker commented on June 2, 2024

Thanks @alombarte it is working but not fitting my scenario as I am using Krakend as proxy for the backends. Looks like no-op cannot be used for endpoints with more than one backend.

from krakend-ce.

alombarte avatar alombarte commented on June 2, 2024

If you need no-op then you must use a Lua script. This can give you an idea of how to do it:

https://www.krakend.io/docs/enterprise/backends/lambda/#canary-testing-of-lambda-functions

from krakend-ce.

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.