I'm building a JHipster microservice application, consisting of Microservice, Registry and Gateway (React). In the Microservice application I can use the application.yml / ApplicatioProperties.java to add properties (such as API keys) which may change between environments (Dev, Prod etc).
My question is, can I do the same thing on the React front-end? This is a Spring application so the same application.yml and ApplicationProperties.java are in place. Does anyone have a code example of surfacing custom properties to the UI?
There's an AuthInfoResource that takes properties and makes them available at an /api/auth-info
endpoint. You could so something similar to expose configuration properties to your React app.
package <%= packageName %>.web.rest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Resource to return information about OIDC properties
*/
@RestController
@RequestMapping("/api")
public class AuthInfoResource {
@Value("${spring.security.oauth2.client.provider.oidc.issuer-uri:}")
private String issuer;
@Value("${spring.security.oauth2.client.registration.oidc.client-id:}")
private String clientId;
@GetMapping("/auth-info")
public AuthInfoVM getAuthInfo() {
return new AuthInfoVM(issuer, clientId);
}
class AuthInfoVM {
private String issuer;
private String clientId;
AuthInfoVM(String issuer, String clientId) {
this.issuer = issuer;
this.clientId = clientId;
}
public String getIssuer() {
return this.issuer;
}
public void setIssuer(String issuer) {
this.issuer = issuer;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.