Skip to content

Commit

Permalink
fix: support sitemap locations for muliple servers
Browse files Browse the repository at this point in the history
  • Loading branch information
jometzner committed Nov 30, 2021
1 parent f1af366 commit bbf98ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
33 changes: 25 additions & 8 deletions nginx/templates/multi-channel.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
rewrite '^((.*){{ .path }})$' '$1{{$identityProvider}}';
{{- end}}

{{- define "LOCATION_TEMPLATE_FOR_SITEMAP" }}
{{- $icmBaseUrl := getenv "ICM_BASE_URL" }}
{{- $baseHref := ""}}{{ if (has . "baseHref")}}{{ $baseHref = .baseHref }}{{end}}
{{- $channel := .channel }}
{{- $application := "rest" }}{{ if (has . "application") }}{{ $application = .application }}{{ end }}
{{- $lang := "en_US" }}{{ if (has . "lang") }}{{ $lang = .lang }}{{ end }}
{{- if $icmBaseUrl }}
proxy_pass {{ $icmBaseUrl }}/INTERSHOP/static/WFS/{{ $channel }}/{{ $application }}/{{ $channel | strings.ReplaceAll "-Site" "" }}/{{ $lang }}/sitemaps/pwa/sitemap_;
{{- else }}
rewrite ^{{ $baseHref }}/sitemap.*$ {{ $baseHref }}/;
{{- end -}}
{{- end }}

{{- range $domain, $mapping := (ds "domains") }}
server {
server_name ~^{{ $domain }}$;
Expand Down Expand Up @@ -153,29 +166,33 @@ server {
location / {
{{- tmpl.Exec "LOCATION_TEMPLATE" $mapping }}
}
location ^~ /sitemap_ {
{{- tmpl.Exec "LOCATION_TEMPLATE_FOR_SITEMAP" $mapping }}
}
{{- else -}}
{{ range $mapping }}
location {{ .baseHref }} {
{{- tmpl.Exec "LOCATION_TEMPLATE" . }}
}
location ^~ {{ .baseHref }}{{if not ( .baseHref | strings.HasSuffix "/")}}/{{end}}sitemap_ {
{{- tmpl.Exec "LOCATION_TEMPLATE_FOR_SITEMAP" . }}
}
{{ end }}
{{- if (has ($mapping | jsonpath "$..baseHref") "/") }}
{{- else }}
{{- if (has ($mapping | jsonpath "$..baseHref") "/") }}
{{- else }}
location / {
allow all;
auth_basic off;
{{ $first := index $mapping 0 -}}
rewrite ^/$ "$scheme://$http_host{{ $first.baseHref }}/home" permanent;
rewrite ^(.*)$ "$scheme://$http_host{{ $first.baseHref }}$request_uri" permanent;
}
{{- end -}}
location ^~ /sitemap_ {
{{- tmpl.Exec "LOCATION_TEMPLATE_FOR_SITEMAP" $first }}
}
{{- end -}}
{{- end }}

{{- if (getenv "ICM_BASE_URL") }}
# we have the ICM_BASE_URL so we can include sitemap locations
#
include /etc/nginx/conf.d/sitemap.conf;
{{- end }}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
Expand Down
26 changes: 0 additions & 26 deletions nginx/templates/sitemap.conf.tmpl

This file was deleted.

0 comments on commit bbf98ce

Please sign in to comment.