tarampampam / error-pages

🚧 Pretty server's error pages in the docker image & git repository (for traefik, k8s, nginx and so on)
https://tarampampam.github.io/error-pages/
MIT License
890 stars 82 forks source link

Custom env variables to be used in templates #164

Closed Quasarman closed 1 year ago

Quasarman commented 1 year ago

Is there an existing issue for this?

Describe the problem to be solved

I want to dynamically set the document.domain in my custom template based on the mode I am in. I use different domains for development and production mode. Currently this is the solution I have:

<script>
      {{ if show_details }}
      document.domain = 'local.mydomain.com';
      {{ else }}
      document.domain = 'mydomain.com';
      {{ end }}
</script>

This is not perfect since I actually have 3 states: development, staging and production, each with their own domain. The current solution just handles development and production with the help of the show_details flag since this is turned off in production I can use it to set the domain accordingly.

Suggest a solution

I searched existing issues and also had a peak inside the source code but did not find anything the would allow me to set a custom environment variables that are populated inside the template like so:

...
extraEnv:
  DOMAIN: mydomain.com

that would be available inside the html template:

<script>
      document.domain = '{{domain}}';
</script>

Additional context

If there is a similar existing solution I have missed please let me know.

tarampampam commented 1 year ago

Is #165 can solve this issue?

https://github.com/tarampampam/error-pages/blob/89a9af50c99012afaa16b55095f0e8ae0f3e9199/internal/tpl/render_test.go#L20

https://github.com/tarampampam/error-pages/blob/89a9af50c99012afaa16b55095f0e8ae0f3e9199/internal/tpl/render_test.go#L77-L80

Quasarman commented 1 year ago

Wow that was quick! Yes this would work, thanks 😀

Maybe add some doc example (in the README or somewhere) so other users also know that this is possible.

Otherwise looks great.

tarampampam commented 1 year ago

:fire: Released in v2.20.0