xxx.s500

トップ | 最近の更新 | このサイトについて | rss2.0

[node.js] openshiftでexpressを使う

openshiftとかいうサービス上でexpressを動かすために七転八倒。ひとまず正解をメモしておく。

expressの構成ファイルの修正

package.jsonの変更箇所

  "scripts": {
    "start": "node bin/www"
  },
  "main": "./bin/www",

bin/wwwの変更箇所

/**
 * Get port from environment and store in Express.
 */
var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || '8080');
var ip = process.env.OPENSHIFT_NODEJS_IP;
if (typeof ip === "undefined") {
  //  Log errors on OpenShift but continue w/ 127.0.0.1 - this
  //  allows us to run/test the app locally.
  console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
  ip = "127.0.0.1";
};

app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port, ip);
server.on('error', onError);
server.on('listening', onListening);

作業記録

gitのインストール

freebsd10.1の場合

$ sudo pkg install git
$ git config --global user.name "<ユーザ名>"
$ git config --global user.email "<メールアドレス>"

なんとかKeyの生成

mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa -C "<メールアドレス>"
→全てENTER

.ssh内にid_rsaとid_rsa.pubが生成された

なんとかKeyの登録

openshiftのコントロールパネルのメニューから「Setting」をクリック
「Public Keys」の「Add a new key...」をクリック
「Key name」→適当な名前を入力
「Paste the contents of your public key file」→~/.ssh/id_rsa.pub の内容をコピペ

gitでクローン

[Application]→[クローンしたいアプリを選択]→[Source Code]のコードをどこかに保存。
仮に
ssh://xxxxxxxxxxxxxxxxxxxxxxxxxxxx@yyy-zzzzz.rhcloud.com/~/git/yyy.git/
だったとすると、クローンのコマンドはこんな感じ。

$ git clone ssh://xxxxxxxxxxxxxxxxxxxxxxxxxxxx@yyy-zzzzz.rhcloud.com/~/git/yyy.git/
$ cd yyy/

gitでプッシュ

プッシュしたいデレクトリに入って

$ git add .;git commit -m 'My changes';git push