Sara Taha
Sara Taha

Reputation: 73

How to redirect krakend endpoint?

I have this endpoint config below, I want to redirect / to another static url, currently using this shows invalid host, as there's no backend in place:

- endpoint: "/"
  backend:
  - url_pattern: "/"
    host:
      - {{ .Values.redirect }}

Upvotes: 0

Views: 148

Answers (1)

Albert Garcia
Albert Garcia

Reputation: 187

In most cases, you need to provide a valid host for each backend (unless you've defined a default host in the root configuration). Here's a minimal example of a valid configuration:

$schema: "https://www.krakend.io/schema/krakend.json"
version: 3
name: "My first API Gateway - KrakenD"
port: 8080
endpoints:
  - endpoint: "/"
    output_encoding: "no-op"
    backend:
      - url_pattern: "/hello-world/hello/world"
        host:
          - "https://sandbox.api.service.nhs.uk"

If you're using the Flexible Configuration (FC), it would be helpful to see the rest of your setup, including the settings file and how you're invoking KrakenD. This will ensure everything is correctly in place and that you're defining the FC parameters properly. Otherwise, KrakenD might interpret {{ .Values.redirect }} as a literal string instead of a variable.

I recommend you to take a look at the Flexible Configuration documentation, or at the code examples in our examples repository: https://github.com/krakend/examples/tree/main/3.flexible-configuration/community

Upvotes: 0

Related Questions