How GitLab Pages uses the GitLab API to serve content
How it generates routes
-
Before Gitlab 12.10 the Pages daemon would rely on a file named
config.json
located in your project’s directory, that is/path/to/shared/pages/myproject/myproject.gitlab.io/config.json.
-
Now it use GitLab API-based configuration. the Pages daemon sources the domain configuration via an internal API endpoint
/api/v4/internal/pages?host=myproject.gitlab.io
. The response from the API is very similar to the contents of theconfig.json
file:{ "certificate": "--cert-contents--", "key": "--key-contents--", "lookup_paths": [ { "access_control": true, "https_only": true, "prefix": "/", "project_id": 123, "source": { "path": "myproject/myproject.gitlab.io/public/", "type": "file" } } ] }
How it serves content
gitlab-pages
command optionpages-root
specific Directory where the pages are stored, for example:-pages-root="shared/pages"
- Gitlab domain source configuration specific the
root path
, for example:"path": "myproject/myproject.gitlab.io/public/"
- Use reader.resolvePath to parse
URL.subpath
- Finally we get the file path
shared/pages/myproject/myproject.gitlab.io/public/URL.subpath
to serve
reference
- https://gitlab.com/gitlab-org/gitlab-pages/-/tree/master/
- https://about.gitlab.com/blog/2020/08/03/how-gitlab-pages-uses-the-gitlab-api-to-serve-content/