AngularJS1.5に再挑戦 その5 Local Webserver for AngularJS and Javascript Apps
概要
AngularJS1.5に再挑戦 その5 URL Routing Part 1
参考動画・参考サイト
AngularJS — Superheroic JavaScript MVW Framework
Local Webserver for AngularJS and Javascript Apps
- 以下の動画で、local webserverを立ち上げる必要があるらしい。ruby のgemのrackを使うとのこと。
- git hubの参照用ページはこちら。
Guides/angular_webserver.md at master · codingforentrepreneurs/Guides · GitHub
- 色々必要なものをinstallする。
$ sudo gem install bundler
- Gemfileというファイルを作成して、そこに以下のように、記述する。
source 'https://rubygems.org' gem 'rack'
- bundle installする。
$ bundle install
ここでerror発生!
rack-2.0.1 requires ruby version >= 2.2.2, which is incompatible with the current version, ruby 2.0.0p648
とのこと。なので、rubyを新しいものに変える。rubyを以下の手順で変えてみる。
$ brew install ruby-build $ brew install rbenv $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile $ echo 'eval "$(rbenv init -)"' >> .bash_profile $ source .bash_profile $ rbenv install 2.2.3 $ rbenv global 2.2.3
- 再度、
$ bundle install
。。。。あーこれでもダメだな。どうもbundlerのrubyのversionが古いのかなぁ。。。とりあえず、bundlerを再度今のversionのrubyで、installしておく。あとsudoを外してinstallする。
$ gem install bundler $ bundle install
- できた〜〜!続いて、config.ru というファイルを作成し、以下のコードをコピペする。
use Rack::Static, :urls => ["/images", "/js", "/css", "/templates"], :root => "src" run lambda { |env| [ 200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('src/index.html', File::RDONLY) ] }
$ rackup
をターミナルで実行する。。。うまくいったぽいので、http://localhost:9292/
にアクセスする。(多分ポートは毎回変わるのか?)よし、とりあえず、できた。