Managing Google Cloud App Engine Redirecting Rules (dispatch.yaml)

Osman Kanadikirik
Mar 1 · 2 min read

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 dispatch.yaml

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.

  1. Our file has to start with dispatch: main element.

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.

  1. service The element that defines our which App Engine service will match with the URL pattern that we will define as url field.
dispatch:- url: “toprak.io/*”
service: toprak-web
- url: “api.toprak.io/*”
service: toprak-api
- url: “*/work*”
service: static-backend
- url: “test.toprak.io/*”
service: “toprak-test”

First, we started our dispatch.yaml file with the dispatch: element.

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.

Toprakio

Software Development

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store