2

I wanted to externalise the email templates to send email notifications so I am storing them in a templates folder in GIT repository which is mapped to our spring-cloud-config server.

The templates folder in git repository has some .html files. Can someone help me with the cloud config URL to access .html files.

Abeed Ali
  • 61
  • 2
  • Based on the docs, it only serves config - "Spring Cloud Config Server provides an HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content)" https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html You could add a custom endpoint for serving the templates. – Jon Ruddell Oct 20 '20 at 14:35
  • Unless I misunderstood, it seems it could serve plain text: https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html – Gaël Marziou Oct 20 '20 at 17:50
  • Thanks for the replies @GaëlMarziou I tried the solution mentioned in link https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html I have stored my HTML file as .txt file and tried to access it with URL http:///{name}/{profile}/{label}/samplehtml.txt but I was getting application.yml level config details instead of samplehtml.txt details I am actually using JHipster registry as a spring-cloud-config, as per the spring-docs we should get .txt file. Do we need to add any additional configs to access plain text files? – Abeed Ali Oct 22 '20 at 06:07
  • @GaëlMarziou I am able to access configuration of YAML equivalent content. I am facing issues only while accessing non YAML equivalent files i.e., .html, .txt, etc. Can you please let me know, to access these files through spring-cloud-config do we need any additional configuration in my Jhipster Registry ? Thanks in advance – Abeed Ali Oct 22 '20 at 06:13
  • @JonRuddell, thanks for the reply. I am using Jhipster Registry as spring-cloud-config server, The custom endpoint you suggested does it has to access the .html template files directly through GIT or is there any other way to access them ? – Abeed Ali Oct 22 '20 at 06:33

1 Answers1

0

Generate App

For example, taking a default microservice app with a baseName of ms created with jh import-jdl --inline "application { config { applicationType microservice, baseName ms } }"

Add HTML File

Add a file src/main/docker/central-server-config/localhost-config/example.html:

<html><body><h1>${configserver.name}</h1></body></html>

Start the JHipster Registry

Start the JHipster Registry with docker-compose -f src/main/docker/jhipster-registry.yml up -d which will serve the config and HTML file we created.

Request the HTML File

To access this file through the JHipster Registry, you can use the following URL. Any variables in the templates will be replaced with the config variable present in the JHipster Registry config file. The format is: http://user:password@registry-url:8761/config/app-name/profile/git-label/example.html:

curl http://admin:admin@localhost:8761/config/ms/prod/master/example.html

Which will return:

<html><body><h1>Docker JHipster Registry</h1></body></html>
Jon Ruddell
  • 6,244
  • 1
  • 22
  • 40