Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nginx-website): allow setting redirections #1332

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/nginx-website/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description: A Helm chart for serving website with nginx
name: nginx-website
maintainers:
- name: lemeurherve
version: 0.2.0
version: 0.3.0
7 changes: 7 additions & 0 deletions charts/nginx-website/templates/nginx-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ data:
try_files {{ .Values.nginx.slashLocation.tryFiles }};
{{- end}}
}
{{- if .Values.nginx.redirections }}
{{- range .Values.nginx.redirections }}
location {{ .location }} {
return {{ .returnedCode }} {{ .destination}}$request_uri;
}
{{- end}}
{{- end}}
}
19 changes: 19 additions & 0 deletions charts/nginx-website/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ set:
index: custom.html
autoindex: "off"
tryFiles: $uri /index.html
redirections:
- location: /alocation
returnedCode: 301
destination: https://awebsite.example/apath/
- location: /anotherlocation
returnedCode: 302
destination: https://anotherwebsite.example/anotherpath/
service:
port: 8080
tests:
Expand Down Expand Up @@ -54,3 +61,15 @@ tests:
- matchRegex:
path: data["default.conf"]
pattern: 'try_files \$uri /index.html;'
- matchRegex:
path: data["default.conf"]
pattern: 'location /alocation {'
- matchRegex:
path: data["default.conf"]
pattern: 'return 301 https://awebsite.example/apath/\$request_uri;'
- matchRegex:
path: data["default.conf"]
pattern: 'location /anotherlocation {'
- matchRegex:
path: data["default.conf"]
pattern: 'return 302 https://anotherwebsite.example/anotherpath/\$request_uri;'
3 changes: 3 additions & 0 deletions charts/nginx-website/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ tests:
- notMatchRegex:
path: data["default.conf"]
pattern: 'try_files \$uri /index.html;'
- notMatchRegex:
path: data["default.conf"]
pattern: 'return .*;'
5 changes: 5 additions & 0 deletions charts/nginx-website/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ nginx:
autoindex: "on"
## Uncomment to enable try_files directive
# tryFiles: $uri /index.html
redirections: {}
## Example:
# - location: /plugin-installation-trend
# returnedCode: 301
# destination: https://raw.githubusercontent.com/jenkins-infra/infra-statistics/gh-pages/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the same API and may still cause breaking changes.

  1. There's no guarantee that consumers will follow redirects
  2. raw.githubusercontent returns a content-type of text/plain which may break consumers