【问题标题】:How to configure TLS @improbable-eng/grpc-web for NextJS based application?如何为基于 NextJS 的应用程序配置 TLS @improbable-eng/grpc-web?
【发布时间】:2021-05-18 19:44:38
【问题描述】:

我正在使用 NextJS 构建我的 Web 应用程序,使用 https://github.com/improbable-eng/grpc-web 在后端和前端之间进行通信。 以下 React 元素使用grpc.invoke 与 GRPC 后端服务进行通信:

export default function Index({user}: OverviewProps) {

    useEffect(() => {
        grpc.invoke(RepoService.ListRepos, {
            host: "http://localhost:9000",
            request: listReq,
            onMessage: (msg) => {
                console.log(msg);
            },
            onEnd:(code:grpc.Code,msg:string | undefined | number, trailers: grpc.Metadata)=>{
                console.log(code);
                if(code == grpc.Code.OK){
                    console.log("Worked")
                }else{
                    console.log("Not Working")
                }
            },
            debug: true

        })

    }, [])

    return wrapWithLayout(
        <p>Hi {user.nickname}</p>
    );
}

后端服务受 TLS 保护。在客户端,我必须以某种方式将证书加载到客户端中。问题是,如何将证书加载到客户端才能与后端服务通信?

【问题讨论】:

    标签: reactjs next.js grpc-web


    【解决方案1】:

    在浏览器客户端中,必须在浏览器级别配置任何 TLS 选项,因为我们无法像您在其他平台上那样访问底层网络。这实质上意味着您需要使用公开可接受的证书(例如 Let's Encrypt 或直接从 CA 购买的证书)配置您的服务器。

    Source

    【讨论】:

    • 假设,当我选择使用Let's Encrypt 时,我到底要做什么?
    • 这是一个相当广泛的话题,值得单独提出一个问题。虽然我很确定一个简单的搜索会为你解答。编辑:Let's Encrypt 没有什么特别之处——除了它是一个使用 ACME 协议颁发证书的免费提供商。
    猜你喜欢
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 2011-09-11
    • 2020-08-15
    • 2012-05-05
    相关资源
    最近更新 更多