DEV Community

tackme
tackme

Posted on • Edited on

2 2

JSSのIntegrated ModeでConnected GraphQLを使用すると証明書エラーが発生する

JSSでウェブサイトを作成していた際にGraphQLで詰まったので備忘録として残しておきます。

Integrated GraphQLだと動的にパラメータを変更するような処理が組めないので、そういう場合はConnected GraphQLを使うことになります。

しかし、Connected GrapQLを使用したコードをSitecoreへデプロイしてIntegrated Modeで動作させると以下のようなエラーが発生します。

unable to verify the first certificate
Enter fullscreen mode Exit fullscreen mode

これはnode.jsはWindowsの証明書ストアを参照しないため、SSRの実行時にAPIへのリクエストで証明書の検証に失敗することが原因です。

対応方法

まずはウェブサイトの中間(ルート)証明書をブラウザから取得します。

証明書の形式は Base 64 encoded X.509 (.CER) を選択してください。

次にその証明書を適当なフォルダに配置します。

最後にSitecore.configへ以下のパッチを適用します。JSSで使用するNode.jsのプロセスに環境変数 NODE_EXTRA_CA_CERTS を割り当てています(システム環境変数に直接設定してもOKです)。

<configuration xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore role:require="ContentManagement or ContentDelivery or Standalone">
    <javaScriptServices>
      <renderEngines>
        <renderEngine name="nodejs">
          <instance id="defaults">
            <!-- 証明書のパスを指定 -->
            <EnvironmentVariables>
              <var name="NODE_EXTRA_CA_CERTS" value="C:\path\to\certificate.cer" />
            </EnvironmentVariables>
          </instance>
        </renderEngine>
      </renderEngines>
    </javaScriptServices>
  </sitecore>
</configuration>
Enter fullscreen mode Exit fullscreen mode

node.jsでは環境変数のNODE_EXTRA_CA_CERTSに証明書ファイルへのパスを設定しておくことで、node.jsがその証明書を参照するようになります。

これでエラーが発生せずにConnected GrapQLを使用できるようになります。

参考

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs