> For the complete documentation index, see [llms.txt](https://takahitomiyamoto.gitbook.io/heroku-basic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://takahitomiyamoto.gitbook.io/heroku-basic/toc/level-2/build-your-first-app-with-lwc-oss.md).

# Build Your First Application with LWC OSS

## 進め方

次のURLにアクセスし、指示に従って進めてください。

> <https://trailhead.salesforce.com/ja/content/learn/projects/build-your-first-app-with-lightning-web-components-open-source>

## Herokuへのデプロイ

Trailheadで作成したアプリをHerokuへデプロイするためには、いくつか追加設定が必要です。

Procfileを作成して配置します。

{% tabs %}
{% tab title="Procfile" %}
{% code title="Procfile" %}

```
web: npm run start:client

```

{% endcode %}
{% endtab %}
{% endtabs %}

画面に表示するデータの提供元が外部サイトであるため、[**Content Security Policy**](https://developer.mozilla.org/ja/docs/Web/HTTP/CSP) に引っかからないようにする必要があります。

`scripts/server.js` のコードを一部修正します。

{% tabs %}
{% tab title="JavaScript" %}
{% code title="scripts/server.js" %}

```javascript
...

const app = express();
// app.use(helmet());
app.use(
  // Sets all of the defaults, but overrides img-src and script-src
  helmet.contentSecurityPolicy({
    directives: {
      ...helmet.contentSecurityPolicy.getDefaultDirectives(),
      'img-src': ["'self'", 'https://developer.salesforce.com'],
      'connect-src': ["'self'", 'https://conference-lwc-app.herokuapp.com']
    }
  })
);
app.use(compression());

...
```

{% endcode %}
{% endtab %}
{% endtabs %}

あとは、Lv.1で学習した内容と同じです。

{% hint style="info" %}
Herokuアプリの名前は、世界中で一意であれば自分の好きな文字列を指定することができます。先頭は英字にしてください。

例）wed-20210407-lv2-1-abcde
{% endhint %}

{% tabs %}
{% tab title="Console" %}

```bash
heroku create "好きな文字列"

# ローカルで動作確認
npm run build:development
heroku local web

git add .
git commit -m "Lv.2-1 completed"
git push heroku main

heroku open -a "好きな文字列"

```

{% endtab %}
{% endtabs %}

ローカルと同じ動作になってることを確認できたらOKです。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://takahitomiyamoto.gitbook.io/heroku-basic/toc/level-2/build-your-first-app-with-lwc-oss.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
