Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

環境

  • 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

susieyy
フリーランス - スタートアップエンジニアリングアドバイザー - iOS技術顧問 - プロトタイプ開発
https://susieyy.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした