---
title: "ヘッドレスサイトにJSSアプリをインポートしてください"
slug: "import-a-jss-app-into-your-headless-site"
abstract: "JSSアプリケーションのデプロイ方法を学びましょう。"
---
# ヘッドレスサイトにJSSアプリをインポートしてください

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

> !重要JSSアプリをインポートする前に、[Sitecore JavaScriptサービスSDK(JSS)](https://doc.sitecore.com/xp/en/developers/hd/20/sitecore-headless-development/sitecore-javascript-services-sdk--jss-.html)に記載された手順を必ず確認してください。アプリのサイトやホスト名の設定も含まれます。

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

1.  APIキーを作成し、そのアイテムIDをアプリ設定時に記録してください。
    
2.  レイアウトサービスが動作しているかをテストするには、Sitecoreホストのレイアウトサービスにテストリクエストを行ってください。 http://myapp.siteco.re/sitecore/api/layout/render/jss?item=/&amp;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を入力します。
        
    -   デプロイメントシークレット:ここにシークレットを入力するか、エンターキーを押して作成してください。新しいデプロイシークレットを作成する場合は、コンテンツエディター(JSS site/Settings)で入力する必要があります。
        
        ![Headless Deployment secret](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/sxa/102/sitecore-experience-accelerator/images/SXA-deployment-secret.png)
        
    
    > !重要JSS上でSXA展開を行っているため、設定展開のステップを省略できます。
    
4.  ウェブアプリケーションでGraphQLを使いたい場合は、サイトの*Settings*項目を開き、*GraphQL endpoint*フィールドの値を /sitecore/api/graph/edgeに置き換えてください。以下の例パッチを利用できます。URLとテンプレートパスは必ず更新してください。
    
    <!--
     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項目に追加する必要があります。
    
    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インポートユーザーが正しい権限を持っている必要があります。ユーザーが正しい権限を持っているか確認するには、コンテンツエディターに行き、 アイテムを選択し、セキュリティセクションで「セキュリティを割り当てる」をクリックしてください。「セキュリティ権限を割り当てる」ダイアログで *sitecore\\JssImport* ユーザーを選択し、 *Items* と *Descendants*の両方に対して書き込み権限を持っていることを確認してください。