JSSアプリをヘッドレス サイトにインポートする

Version: 10.2
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

JSSアプリケーションをSXA環境にデプロイする場合、一般的なアプリのデプロイ プロセスにはいくつかの違いがあります。JSSサイトの作成では、デフォルトの構成設定がitems (Site/Settings/) に追加されるため、jss.sitecore.comで説明する一般的なプロセスのConfig Deploymentステップをスキップする必要があります。GraphQLエンドポイントを定義する必要があるため、Config Deploymentステップを使用する場合は、設定でアプリノードとサイトノードをコメントアウトする必要があります。

大事な

JSSアプリをインポートする前に、アプリのサイトやホスト名の設定など、Sitecore JavaScriptレンダリングSDK (JSS) で説明されている手順に従う必要があります。

JSSアプリをヘッドレス サイトにインポートするには:

  1. APIキーを作成し、アプリの設定に使用するアイテムIDをメモします。

  2. Layout Serviceが機能しているかどうかをテストするには、SitecoreホストのLayout Serviceにテスト リクエストを行います。 http://myapp.siteco.re/sitecore/api/layout/render/jss?item=/&sc_apikey={YOUR_API_KEY_ID}

  3. Sitecore接続を設定するには、JSSアプリ内のコマンド ラインでjss setupを実行し、プロンプトに従います。プロンプトでは、次の情報の入力を求められます。

    • Sitecoreフォルダーへのパス: 以前に作成したヘッドレス サイトへのパスを入力します。たとえば、C:\inetpub\wwwroot\sxa92のようになります。

    • ホスト名: SXAサイトのホスト名を入力します。たとえば、http://sxa92のようになります。

    • インポート サービスURL: 既定の設定を変更する必要はありません。たとえば、http://sxa92/sitecore/api/jss/importのままにします。

    • APIキー: APIキーのGUIDを入力します。

    • デプロイシークレット: ここにシークレットを入力するか、Enterキーを押してシークレットを作成します。新しいデプロイメントシークレットを作成する場合は、コンテンツエディター(JSS site/Settings)に入力する必要があります。

      Headless Deployment secret
    大事な

    JSSでSXAデプロイメントに取り組んでいるため、設定デプロイメントのステップをスキップできます。

  4. WebアプリケーションにGraphQLを使用する場合は、サイトのSettingsアイテムを開き、GraphQL endpointフィールドの値を /sitecore/api/graph/edgeに置き換えます。以下のサンプルパッチを使用できます。URLとテンプレートパスを必ず更新してください。

    RequestResponse
    <!--
      JSS Sitecore Configuration Patch File
    
      This configuration file registers the JSS site with Sitecore, and configures the Layout Service
      to work with it. Config patches need to be deployed to the Sitecore server.
    
      Normally `jss deploy config` can do this for local development. To manually deploy, or to deploy via CI,
      this file can be placed in the `App_Config/Include` folder, or a subfolder of it, within the Sitecore site.
    -->
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
      <sitecore>
        <api>
          <!--
            Define the app's Sitecore GraphQL API endpoint
            Note: this can be removed if you are not using GraphQL.
            Note: the endpoint must be defined both for integrated and connected type GraphQL queries.
          -->
          <GraphQL>
            <endpoints>
              <carsGraphQLEndpoint url="/api/cars" type="Sitecore.Services.GraphQL.Hosting.DatabaseAwareGraphQLEndpoint, Sitecore.Services.GraphQL.NetFxHost" resolve="true">
                <url>$(url)</url>
    
                <enabled>true</enabled>
                <enableSubscriptions>true</enableSubscriptions>
    
                <!-- lock down the endpoint when deployed to content delivery -->
                <graphiql role:require="ContentDelivery">false</graphiql>
                <enableSchemaExport role:require="ContentDelivery">false</enableSchemaExport>
                <enableStats role:require="ContentDelivery">false</enableStats>
                <enableCacheStats role:require="ContentDelivery">false</enableCacheStats>
                <disableIntrospection role:require="ContentDelivery">true</disableIntrospection>
    
                <schema hint="list:AddSchemaProvider">
                  <content type="Sitecore.Services.GraphQL.Content.ContentSchemaProvider, Sitecore.Services.GraphQL.Content">
                    <!-- scope typed template generation to just this app's templates -->
                    <templates type="Sitecore.Services.GraphQL.Content.TemplateGeneration.Filters.StandardTemplatePredicate, Sitecore.Services.GraphQL.Content">
                      <database>context</database>
                      <paths hint="list:AddIncludedPath">
                        <templates>/sitecore/templates/Project/Demo</templates>
                      </paths>
                      <fieldFilter type="Sitecore.Services.GraphQL.Content.TemplateGeneration.Filters.StandardFieldFilter, Sitecore.Services.GraphQL.Content">
                        <exclusions hint="raw:AddFilter">
                          <!--
                              Remove system fields from the API (e.g. __Layout) to keep the schema lean
                          -->
                          <exclude name="__*" />
                        </exclusions>
                      </fieldFilter>
                    </templates>
    
                    <queries hint="raw:AddQuery">
                      <!-- enable querying on items via this API -->
                      <query name="item" type="Sitecore.Services.GraphQL.Content.Queries.ItemQuery, Sitecore.Services.GraphQL.Content" />
                    </queries>
    
                    <fieldTypeMapping ref="/sitecore/api/GraphQL/defaults/content/fieldTypeMappings/standardTypeMapping" />
                  </content>
                </schema>
    
                <!-- Enables the 'jss' graph nodes that are preformatted to use with JSS rendering components, and the datasource resolving queries for JSS -->
                <extenders hint="list:AddExtender">
                  <layoutExtender type="Sitecore.JavaScriptServices.GraphQL.JssExtender, Sitecore.JavaScriptServices.GraphQL" resolve="true" />
                </extenders>
    
                <!-- Determines the security of the service. 'publicService' is open to anonymous access, but requires an SSC API key. -->
                <security ref="/sitecore/api/GraphQL/defaults/security/publicService" />
    
                <!-- Determines how performance is logged for the service. Defaults are defined in Sitecore.Services.GraphQL.config -->
                <performance ref="/sitecore/api/GraphQL/defaults/performance/standard" />
              </carsGraphQLEndpoint>
            </endpoints>
          </GraphQL>
        </api>
      </sitecore>
    </configuration>
    
  5. JSSアプリケーションで使用するレイアウト サービス設定をsxa-jssに変更します。

    • Next.jsの場合: \src\liv\layout-service-factory.rest.tsファイルで、configurationNameプロパティを 'sxa-jss'に更新します。

    • Reactの場合: \src\lib\layout-service-factory.jsファイルで、configurationNameプロパティを 'sxa-jss'に更新します。

    • Angularの場合: \src\app\lib\layout-service-factory.tsファイルで、configurationNameプロパティを 'sxa-jss'に更新します。

    • Vueの場合: \src\lib\layout-service-factory.jsファイルで、configurationNameプロパティを 'sxa-jssに更新します。

    次のコード例は、Reactで 'sxa-jss' を追加するとどのように見えるかを示しています。AngularとVueの場合は、スニペットをlayoutServiceConfigアイテムにも追加する必要があります。

    RequestResponse
    export class LayoutServiceFactory {
      create(): LayoutService {
        return new RestLayoutService({
          apiHost: config.sitecoreApiHost,
          apiKey: config.sitecoreApiKey,
          siteName: config.jssAppName,
          configurationName: 'sxa-jss',
        });
      }
    }
  6. アプリをインポートするには、JSSアプリ内でコマンド プロンプト/ターミナルを開き、次のコマンドを実行します。

    jss deploy app --includeContent --includeDictionary

メモ

インポートを機能させるには、JSSインポート ユーザーに適切なアクセス許可が必要です。ユーザーに適切な権限があることを確認するには、コンテンツ エディターに移動し、<site>アイテムを選択し、SecurityセクションでAssign securityをクリックします。 Assign Security Rightsダイアログで、sitecore\JssImportユーザーを選択し、ItemsDescendantsの両方に対する書き込み権限があることを確認します。

何かフィードバックはありますか?

この記事を改善するための提案がある場合は、