Managing Google Cloud App Engine Redirecting Rules (dispatch.yaml)
If you have an application running on the App Engine service of the Google Cloud cloud provider and you want to distribute the requests to this application among your App Engine services, we can do this with the rules we write in the file named
NOTE: The dispatch.yaml file must be located in the root directory of your project or in the same directory as your default App Engine service. You can only have 1 dispatch.yaml file.
Dispatch.yaml File Syntax
The dispatch.yaml file has a very simple syntax. There is a template we must follow. After knowing this template, we can write our routing rules as we wish.
- Our file has to start with
- In the rules we will define, we have to use HTTP URL patterns with dots to separate subdomains.
- Ordering is important in the rules we will define. If we have 2 matching rules for the same URL, the first of them will be valid.
Now that we have learned the first 3 rules to pay attention to, we can begin to define our rules.
Each rule we will define includes 2 elements.
serviceThe element that defines our which App Engine service will match with the URL pattern that we will define as
urlThe element between the quotation marks that determines which URL pattern this rule will apply to.
dispatch:- url: “toprak.io/*”
service: toprak-web- url: “api.toprak.io/*”
service: toprak-api- url: “*/work*”
service: static-backend- url: “test.toprak.io/*”
First, we started our dispatch.yaml file with the
In the first rule, we define that our “toprak-web” service will handle requests to the URL “toprak.io”.
NOTE: The “*” sign we will add after the “/” sign includes all the directories that will come after that directory. If we add the “*” sign before the “/” sign, it will include all domains that will be added before that directory. You can see an example of this in our 3rd rule definition.
In the second rule, we define that our “toprak-api” service will handle all requests for our subdomain “api.toprak.io”.
In the third rule, we are doing this:
Our service named “static-backend” will handle the requests of any domain name or sub-domain name to all URLs that start with the “/ work” directory and contain any directory after this directory.
In the fourth and last rule, we define that our “toprak-test” service will handle all the requests that will come to our “test.toprak.io” sub-domain.
In this way, we can redirect different services of an application running on the Google Cloud App Engine service to different URLs.
You can send all the questions you have in mind, either as a comment or by e-mail. See you with more different and always teaching content.