0

well I need create a endpoint where can create a user, using express-gateway, in this have 2 ports running.

  1. gateway http server listening on :::8181
  2. admin http server listening on 127.0.0.1:9876

I can create a user sending my information to:

http://127.0.0.1:9876/users

I can't use this how my end point because have other configuration on my frontend, so in my frontend send my information for create user to:

http://localhost:8181/api/user/create

Now I need send my information to this http://localhost:8181/api/user/create and redirect internal in the gateway to this http://127.0.0.1:9876/users, I try something but just have bad gateway or not found. I call this end point users, so this is the script.

http:
  port: 8181
admin:
  port: 9876
  host: localhost
apiEndpoints:
  events:
    host: localhost
    paths: ["/api/events*", "/swagger*"]
    methods: ["GET", "PATCH"]
  users:
    host: localhost
    paths: "/api/user/create*"
    url: "http://localhost:9876"
    methods: ["POST", "OPTIONS"]
  eventsCreate:
    host: localhost
    paths: "/api/events*"
    methods: ["POST", "PUT", "OPTIONS"]
  auth:
    host: localhost
    paths: "/api/auth*"
    methods: ["POST", "GET", "OPTIONS"]
serviceEndpoints:
  auth:
    url: "http://localhost:59868"
  events:
    url: "http://localhost:5000"
  users:
    url: "http://localhost:9876"
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
  - jwt
  - request-transformer
pipelines:
  authPipeline:
    apiEndpoints:
      - auth
    policies:
      - cors:
      - log:
          action:
            message: "auth ${req.method}"
      - proxy:
          action:
            serviceEndpoint: auth
            changeOrigin: true
  eventsPipeline:
    apiEndpoints:
      - events
    policies:
      - cors:
      - log:
          action:
            message: "events ${req.method}"
      - proxy:
          action:
            serviceEndpoint: events
            changeOrigin: true
  usersPipeline:
    apiEndpoints:
      - users
    policies:
      - cors:
      - log:
          action:
            message: "users ${req.method}"
      - proxy:
          action:
            serviceEndpoint: users
            changeOrigin: true
  userPipeline:
    apiEndpoints:
      - events
    policies:
      - cors:
      - log:
          action:
            message: "events ${req.method}"
      - proxy:
          action:
            serviceEndpoint: events
            changeOrigin: true
  eventsCreatePipeline:
    apiEndpoints:
      - eventsCreate
    policies:
      - cors:
      - log:
          action:
            message: "events ${req.method}"
      - jwt:
          action:
            secretOrPublicKey: "MORTADELAIsMyPassion321"
            checkCredentialExistence: false
      - proxy:
          action:
            serviceEndpoint: events
            changeOrigin: true
CoolLife
  • 1,419
  • 4
  • 17
  • 43

1 Answers1

0

You are trying to map the incoming URL http://localhost:8181/api/user/create to the Express Gateway administration URL http://localhost:9876/users, but your proxy policy only changes the hostname and port components of the URL, not the path.

This is described in the Path Management section of the Proxy documentation. To change the path, you'll need to either adjust the existing users service endpoint or create a new one, and add some instructions to the proxy middleware configuration:

For example, add a new ServiceEndpoint called userCreate:

serviceEndpoints:
  auth:
    url: "http://localhost:59868"
  userCreate:
    url: "http://localhost:9876/users"
  users:
    url: "http://localhost:9876"

And then refer to the new service endpoint and set stripPath in the proxy configuration:

      - proxy:
         action:
            serviceEndpoint: userCreate
            changeOrigin: true
            stripPath: true
James McLeod
  • 2,381
  • 1
  • 17
  • 19