LoginSignup
10
11

More than 5 years have passed since last update.

RESTfulAPIのFrontWebをAngular.jsで構築する準備

Last updated at Posted at 2014-12-30

環境

  • node.js v0.11.14
  • npm v2.1.11
  • bower v1.3.12
  • grunt cli v0.1.13
  • Yeoman v1.3.3
  • Angular.js
  • Bootstrap3

インストール

nodeとnpmをインストールします。

$ brew install node
$ brew install npm

npmで以下ライブラリをインストールします。

$ npm install -g yo grunt-cli bower generator-angular

ジェネレート

Yeomanで雛形プロジェクトをジェネレートします。

$ mkdir Test
$ cd Test
$ yo angular --minsafe [YOUR_APP_NAME]

angular-bootstrapを追加しておきます。

$ bower install angular-bootstrap --save

開発用RESTFulAPIサーバへのProxy設定

/apiというPrefixでパスにアクセスした場合に、localhostの3000ポートにプロキシする設定を行います。

Grunt.js
    // The actual grunt server settings
    connect: {
      options: {
        port: 9000,
        hostname: 'localhost',
        livereload: 35729
      },
      // 追加 ここから
      proxies: [
        {
          context: '/api',
          host: 'localhost',
          port: 3000
        }
      ],
      // 追加 ここまで      
      livereload: {
        options: {
          open: true,
          middleware: function (connect) {
            return [
              require('grunt-connect-proxy/lib/utils').proxyRequest, // 追加 
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },

サーバ起動

localhostの9000ポートでアクセスできるようになります。

$ cd Test
$ grunt serve

REF

10
11
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
10
11