JHipster React前端(网关)应用程序属性 [英] JHipster React Front End (Gateway) Application Properties

查看:59
本文介绍了JHipster React前端(网关)应用程序属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个JHipster微服务应用程序,该应用程序由微服务,注册表和网关(反应)组成. 在微服务应用程序中,我可以使用application.yml/ApplicatioProperties.java添加可能在环境(Dev,Prod等)之间更改的属性(例如API密钥).

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).

我的问题是,我可以在React前端上做同样的事情吗?这是一个Spring应用程序,因此具有相同的application.yml和ApplicationProperties.java.没有人有将自定义属性显示到UI的代码示例吗?

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;
        }
    }
}

这篇关于JHipster React前端(网关)应用程序属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆