I used to have an Nginx proxy that would do below :
location /api {
proxy_pass http://www.myapiexample.com;
}
Then if I made a request to my website at www.example.com/api, it would take me to http://www.myapiexample.com.
With the app engine, and I'm using Nodejs as my backend, how I can achieve the same?
Can't find anything in the docs
UPDATE : If I'm understanding correctly, I can't have my Nginx anymore, so I need to find a way to have the same proxying functionality with App Engine.
You can use dispatch.yaml configuration file if both of your web and api modules are on app engine. dispatch.yaml sends incoming requests to a specific service depending on the path or hostname in the URL.
dispatch:
# Default service serves simple hostname request.
- url: " example.com"
service: default
# Send all api traffic to the api backend.
- url: "*/api/*"
service: api-backend
You can read more about how to use dispatch file.
If your api module is not on app engine you can redirect requests on application level
dispatch:
# Send all api traffic to the api backend.
- url: "*/api/*"
script: router.py
You can write your routing code in router.py something like
class RouteHandler(webapp.RequestHandler):
def get(self):
self.redirect("http://www.myapiexample.com;", True)
Related
I'm having an Google App Engine service residing at https://service-dot-myproject.uc.r.appspot.com/
However I want it to be reachable via https://app.mydomain.com
I have set up the DNS for mydomain.com on Cloudflare and added the custom domain mapping in app engine and set up a dispatch.yaml file
- url: "app.mydomain.com/*"
service: service
Is there a way to somehow map
https://service-dot-myproject.uc.r.appspot.com -> https://app.mydomain.com ?
currently https://app.mydomain.com only resolves to defaultservice
The following dispatch.yaml file resolved the issue
dispatch:
- url: "app.mydomain.com/*"
service: service
Also the file must be separatly deployed via:
gcloud app deploy dispatch.yaml
I am in a situation where I have one app engine service (service-a) that needs to handle a particular path (domain.com/some/particular/path) and I have another app engine service on the same domain (service-b) that needs to handle all other traffic to that domain (domain.com/*).
I've tried structuring my dispatch.yaml as follows, however no matter what I do the domain.com/some/particular/path ends up getting handled by service-b rather than service-a. In other words, all paths are being routed to service-b.
dispatch:
- url: "domain.com/some/particular/path"
service: service-a
- url: "domain.com/*"
service: service-b
How can I handle this situation?
This seems to be more about your code than the dispatch.yaml file that is roting to service-b. For example, I deployed two services, service 1:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello():
return 'Service 1'
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
And service 2:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello():
return 'Service 2'
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
With the following dispatch.yaml:
dispatch:
- url: "domain.com/app2/"
service: app2
- url: "domain.com/*"
service: default
If I try to access to domain.com/app2/ it shows NOT FOUND error message. If I change the routing in service 2 from #app.route('/') to #app.route('/app2') it works like a charm.
I think that your dispatch.yaml redirects to your service-a but the code inside that service redirects to domain.com.
BTW, if inside your services all your .yaml files are named app.yaml GAE for an unknown reason redirect to the default service so it's better to name every .yaml as the service it handles.
I am working on Angular 1 based web application.
I've deployed a web app with nginx , but couldn't deploy production server in my local env.
So, I want call API from the production server. For example,
I am using RestAngular to call API.
Restangular.all('api/user/profile').post(mUser)
This calls
localhost:8080/api/user/profile
because I've deployed a web app in localhost:8080.
I want to redirect requests which starts with "/API" to the production server, by config nginx properly.
So, in this case, it should call API server
http://devprod2api/api/user/profile
Other requests that don't start with "API" should go to:
http://localhost:8080/...
Is it something possible by config nginx properly? If possible, how can I do that?
I am not sure what you have tried, but this just needs a simple proxy_pass as far as I see. Add below to your nginx config and it should point all API to the other server. It assumes that a host entry is present for devprod2api
location /api/ {
proxy_pass http://devprod2api/api/;
}
I'm getting this error in browser:
Mixed Content: The page at 'https://{my-site}' was loaded over HTTPS, but
requested an insecure XMLHttpRequest endpoint 'http://{my-api}'. This request
has been blocked; the content must be served over HTTPS.
I know I need to allow https some how. The application uses Gunicorn to run the application on custom Google App Engine Flexible Environment. It also uses flask. Here is my app.yaml:
runtime: custom
env: flex
service: flex-module
entrypoint: gunicorn -b :$PORT main:app
Is it possible to change some setting in the Extensible Service Proxy to allow https in App Engine? Or do I need to get an ssl certificate and key and add the following to my app.yaml:
gunicorn -w3 --certfile=server.crt --keyfile=server.key test:app
Also i'm not sure if i need to add this to a gunicorn.conf.py as in this documentation:
forwarded_allow_ips = '*'
secure_scheme_headers = {'X-APPENGINE-HTTPS': 'on'}
Thanks
As stated in the documentation, Google does not issue SSL certificates for double-wildcard domains that are hosted at appspot.com:
Note: Google recommends using the HTTPS protocol to send requests to your app. Google does not issue SSL certificates for double-wildcard domains that are hosted at appspot.com. Therefore, HTTPS requests must use the string "-dot-" as the URL notation, instead of "." for separating subdomains. You can use the simple "." URL notation with your own custom domains and other HTTP addresses. For more information, see the HTTP and HTTPS examples in the following sections.
So to allow API requests over https and avoid the mixed content browser error, instead of http://version-one.my-app.appspot.com I needed to send request to: https://version-one-dot-my-app.appspot.com
To make HTTPS calls, enable the ssl library for your app by adding the following configuration to the app.yaml file:
libraries:
name: ssl
version: latest
https://google-auth.readthedocs.io/en/latest/user-guide.html
I'm trying to use custom domain with app engine. Everything works fine with localhost and appspot url. But with custom domain endpoints api doesn't work; the API discovery request (https://cc.mdsarowar.me/_ah/api/discovery/v1/apis/conference/v1/rest) returns Not Found with error code 404.
Here is my app.yaml (full code):
- url: /_ah/spi/.*
script: conference.api
secure: optional
And endpoints api (full code):
#endpoints.api( name='conference',
version='v1',
allowed_client_ids=[WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID],
scopes=[EMAIL_SCOPE], hostname = 'cc.mdsarowar.me')
class ConferenceApi(remote.Service):
"""Conference API v0.1"""
........
Thanks in advance.
As per the docs:
Note: Google Cloud Endpoints does not support custom domains.
Edit
There is an open feature request for this so you may want to star it.