🌏
superstatic - AngularJSも使えるNode簡易サーバ
こんにちは、@armorik83です。
先日npm startでWEBサーバを起動させる最小限のことでhttp-serverを紹介しました。これは、AngularJSアプリケーションに使う時html5Mode#がうまく機能しません。
この問題はAngularjs html5Mode true · Issue #80 · nodeapps/http-serverで報告されています。
superstatic
Issueに寄せられていたコメントからsuperstatic#を知り、試してみたら便利だったので、十分http-serverと同じ役目を果たせるとして採用しました。
使い方
$ superstatic
これだけ。簡単。
AngularJSを動かす
AngularJSのhtml5Mode(true)の場合は事前にsuperstatic.jsonを作成し、サーバのrootに置く必要があります。
superstatic.json
{
"routes": {
"/*":"index.html"
}
}
こうすることでhtml5Modeでのルーティングが正しく動作します。
npm start
package.json
{
"scripts": {
"start": "grunt start && cd app && ss --port 8080 --debug true",
"test": "grunt test"
}
}
こんな感じで書いておけば、npm startで動き出すので便利。コンフィグファイルを別名や別ディレクトリに置きたい場合は-cオプション、$ ss -c path/to/file.jsonのようにする。
Discussion