Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Cloud Foundry Deploy時のlocalhostとportの設定

Cloud Foundry Deployの際のlocalhostとportの設定について

今回はexpressのアプリを例にとります。
CFへのdeployでは、環境変数のVCAP_APP_HOSTとVCAP_APP_PORTを用いてエンドポイントを形成する必要があります。
その時、ローカル環境開発を考慮に入れ、2つのパラメータが存在しない場合も対応します。

server/index.js
...
const HOST = process.env.VCAP_APP_HOST || 'localhost'
const PORT = process.env.VCAP_APP_PORT || 3000
app.listen(PORT, HOST)
...

ちなみに

VCAP_APP_HOSTとVCAP_APP_PORTを確認する方法

$ cf ssh <app name>
$ env

以上です。

tamonmon
Software Engineer
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away