ExpressGateway / express-gateway

A microservices API Gateway built on top of Express.js
https://www.express-gateway.io
Apache License 2.0
2.97k stars 344 forks source link

Cross origin requests are only supported for protocol scheme #990

Closed canyuegongzi closed 4 years ago

canyuegongzi commented 4 years ago

Access to XMLHttpRequest at 'localhost:8080/simple-user-center/v1.0/user/login' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. vendor.dll.js:7 POST localhost:8080/simple-user-center/v1.0/user/login net::ERR_FAILED

http:
  port: 8080
  hostname: '127.0.0.1'
admin:
  port: 9876
  host: '127.0.0.1'
apiEndpoints:
  simpleUserCenter:
    host: localhost
    methods: 'GET,POST,PUT'
    paths: '/simple-user-center/*'
  simpleCmsCenter:
    host: localhost
    methods: 'GET,POST,PUT'
    paths: '/simple-cms-center/*'
serviceEndpoints:
  simpleUserCenterApi:
    url: 'http://127.0.0.1:8881'
  simpleCmsCenterApi:
    url: 'http://127.0.0.1:8882'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - jwt
  - proxy
  - rate-limit
  - request-transformer
pipelines:
  simpleUserCenter:
    apiEndpoints:
      - simpleUserCenter
    policies:
      - cors:
          - action:
              origin: '*'
              methods: 'HEAD,PUT,PATCH,POST,DELETE'
              allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept"
              preflightContinue: true
      - log:
          - action:
              message: 'auth ${req}'
      - proxy:
          - action:
              serviceEndpoint: simpleUserCenterApi
              changeOrigin: true
  simpleCmsCenter:
    apiEndpoints:
      - simpleCmsCenter
    policies:
      - log:
          - action:
              message: 'books ${req}'
      - jwt:
          action:
              secretOrPublicKey: 'the-secret-key'
              checkCredentialExistence: false
              jwtExtractor: header
      - request-transformer:
            action:
              body:
                add:
                  user: req.user
      - proxy:
          - action:
              serviceEndpoint: simpleCmsCenterApi
              changeOrigin: true