I want to create an api gateway with express-gateway (https://www.express-gateway.io/). I have a service as "datastore"
and datastore host: mydatastore.us-west-2.compute.amazonaws.com
I want to create a gateway for : mydatastore.us-west-2.compute.amazonaws.com/datastore
So my gateway.config.yml file like that
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
datastore:
host: mydatastore.us.us-west-2.compute.amazonaws.com
methods : [ 'POST', 'GET' ]
paths: ['/' ,'/datastore']
serviceEndpoints:
datastoresrv:
url: 'http://mydatastore.us.us-west-2.compute.amazonaws.com/'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
user:
apiEndpoints:
- datastore
policies:
- proxy:
- action:
serviceEndpoint: datastoresrv
changeOrigin: true
but when I send a request to localhost:8080/ or localhost:8080/datastore I getting 404 status code and message : "Cannot GET /" or "Cannot GET /datastore/"
So how can I solve this error. Please help.
CodePudding user response:
The problem is in the definition of your datastore apiEndpoint; the hostname has to match the API gateway's host name, in your case, localhost:
apiEndpoints:
datastore:
host: localhost
methods : [ 'POST', 'GET' ]
paths: ['/' ,'/datastore']
CodePudding user response:
I am not sure why you wrote user: under the pipelines
I recommend you to change it like below:
Your code:
pipelines:
user:
apiEndpoints:
- datastore
policies:
Recommendation:
pipelines:
- name: datastore
apiEndpoints:
- datastore
policies:
And please use this datastore name in the serviceEndpoints like below
Old one:
serviceEndpoints:
datastoresrv:
url: 'http://mydatastore.us.us-west-2.compute.amazonaws.com/'
Recommendation:
serviceEndpoints:
datastoresrv:
url: 'http://datastore/'
If you still have a trouble, you might try to change the policies like below
policies:
- cors:
- action:
origin: '*'
methods: 'POST,GET,PUT,PATCH,DELETE'
allowedHeaders: 'Content-Type,Origin,Authorization,Host,Accept,X-Requested-With'
preflightContinue: true
- proxy:
- action:
serviceEndpoint: datastoresrv
changeOrigin: true
