5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Synthでpm2などのデプロイツールを使用可能にする

Posted at

自分の中で今とても熱いnode.js製のフレームワークです。
自分の中でしか熱くないみたいなのでqiitaのストック数も全然伸びません。

問題点

Synthなのですが、$ synth serverコマンドでしか開始することができないんですよね。
それではpm2やforever等のツールを使用することができません。
公式では以下のような解決策を提示していました。

app.coffee
app = require "./back/back-app"
port = process.env.PORT || 3000
app.listen port, ->
  console.log "Synth is now listening on port #{port}"

Synthのバックエンドはexpressをラップしているため、このように実は簡単に実行することができます。
しかし、それではコマンド版の機能として提供されているGulpのWatch等が使えないのです!あぁ、コーヒーの神よ!我に御加護を。

解決策

コマンドが叩けないならライブラリの該当メソッドを直接叩けば良いじゃない

(マリー・アントワネット風に)

How to?

app.coffee
commands = require("./back/node_modules/synth/lib/commands")
port = process.env.PORT || 3000

# if you use production, NODE_ENV = "production"
mode = process.env.NODE_ENV || "development"
commands.startServer mode, port

これをbackとかfrontディレクトリがある所に置けば良いです。
後は$ coffee app.coffeeするなり$ pm2 start app.coffee -i maxすれば完璧です。
JavaScriptで書いている人はまぁ頑張って書きなおして下さい(すっとぼけ)

これでpm2のデプロイも動いたため、特に問題はないと思います。
リリース時にはproductionモードにすると色々と便利な機能が動いたり動かなかったりします。
(ソースコードを見る限り、gulpのwatch機能が無効化されるくらい?)
そこら辺気づいたらバンバン作者にissueを投げましょう。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?