-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Add option to use traefik 3. With traefik 3 selected, domains r…
…ule has to be modified, in order to not use syntax like this: PathPrefix(`/url1/`, `/url2/`), and use instead PathPrefix(`/url1/`) || PathPrefix(`/url2/`)
- Loading branch information
1 parent
9026492
commit ed24537
Showing
4 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{%- import "_macros.jinja" as macros -%} | ||
{# Echo all domains of a group, in a Traefik rule #} | ||
{%- macro domains_rule(hosts, path_prefixes=(), paths=()) -%} | ||
Host(`{{ hosts | join("` || Host(`") }}`) | ||
{%- if path_prefixes or paths -%} | ||
&& ( | ||
{%- if path_prefixes -%} | ||
{{ path_prefix_rule(path_prefixes) }} | ||
{%- if paths %} || {% endif %} | ||
{%- endif %} | ||
{%- if paths -%} | ||
{{ path_rule(paths) }} | ||
{%- endif %} | ||
) | ||
{%- endif %} | ||
{%- endmacro %} | ||
|
||
{# Echo all path prefixes in a Traefik rule #} | ||
{%- macro path_prefix_rule(path_prefixes) -%} | ||
{%- for path in path_prefixes -%} | ||
{%- if path.endswith("/") -%} | ||
PathPrefix(`{{ path }}`) | ||
{%- else -%} | ||
PathPrefix(`{{ path }}`) || Path(`{{ path }}`) | ||
{%- endif -%} | ||
{%- if not loop.last %} || {% endif %} | ||
{%- endfor %} | ||
{%- endmacro %} | ||
|
||
{# Echo all paths in a Traefik rule #} | ||
{%- macro path_rule(paths) -%} | ||
{%- for path in paths -%} | ||
Path(`{{ path }}`) | ||
{%- if not loop.last %} || {% endif %} | ||
{%- endfor %} | ||
{%- endmacro %} | ||
|
||
{%- macro odoo(domain_groups_list, paths_without_crawlers, odoo_version, traefik_version) %} | ||
traefik.domain: {{ macros.first_main_domain(domain_groups_list)|tojson }} | ||
{%- call(domain_group) macros.domains_loop_grouped(domain_groups_list) %} | ||
|
||
{#- Route redirections #} | ||
{%- if domain_group.redirect_to %} | ||
traefik.alt-{{ domain_group.loop.index0 }}.frontend.redirect.regex: ^(.*)://([^/]+)/(.*)$$ | ||
traefik.alt-{{ domain_group.loop.index0 }}.frontend.redirect.replacement: $$1://{{ domain_group.redirect_to }}/$$3 | ||
{{- | ||
router( | ||
prefix="alt", | ||
index0=domain_group.loop.index0, | ||
rule=domains_rule(domain_group.hosts, domain_group.path_prefixes), | ||
entrypoints=domain_group.entrypoints, | ||
) | ||
}} | ||
{%- else %} | ||
|
||
{#- Forbidden crawler routers #} | ||
{%- if traefik_version < 3%} | ||
{%- if paths_without_crawlers and not domain_group.path_prefixes %} | ||
traefik.forbiddenCrawlers-{{ domain_group.loop.index0 }}.frontend.headers.customResponseHeaders: | ||
"X-Robots-Tag:noindex, nofollow" | ||
{{- | ||
router( | ||
prefix="forbiddenCrawlers", | ||
index0=domain_group.loop.index0, | ||
rule=domains_rule(domain_group.hosts, paths_without_crawlers), | ||
entrypoints=domain_group.entrypoints, | ||
) | ||
}} | ||
{%- endif %} | ||
{%- endif %} | ||
|
||
{#- Normal routers #} | ||
{%- if paths_without_crawlers != ["/"] or domain_group.path_prefixes %} | ||
{{- | ||
router( | ||
prefix="main", | ||
index0=domain_group.loop.index0, | ||
rule=domains_rule(domain_group.hosts, domain_group.path_prefixes), | ||
entrypoints=domain_group.entrypoints, | ||
) | ||
}} | ||
{%- endif %} | ||
{%- if not domain_group.path_prefixes %} | ||
{%- set longpolling_route = "/longpolling/" if odoo_version < 16 else "/websocket" -%} | ||
{{- | ||
router( | ||
prefix="longpolling", | ||
index0=domain_group.loop.index0, | ||
rule=domains_rule(domain_group.hosts, [longpolling_route]), | ||
entrypoints=domain_group.entrypoints, | ||
port=8072, | ||
) | ||
}} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endcall %} | ||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters