Friday 22 November 2013

angularjs dev setup

NOTE: Assumes nodejs / npm installed

Use http://yeoman.io/ for app scaffolding (yo), build/preview/test (grunt) and manage dependencies (bower)

sudo npm install -g yo            # grunt / bower are dependencies of yo
npm install -g generator-angular  # install generator
yo angular                        # scaffold out a AngularJS project
bower install angular-ui          # install a dependency for your project from Bower
grunt test                        # test your app
grunt serve                       # preview your app
grunt                             # build the application for deployment

For testing, karma is recommended: https://github.com/vojtajina/karma/
sudo npm install -g karma

Adding items to your project
yo angular:controller myController
yo angular:directive myDirective
yo angular:filter myFilter
yo angular:service myService

NOTE: The controller will be named whatever you specify + 'Ctrl', so running 'yo angular:controller About' will create the AboutCtrl controller.

A quick overview of yo/grunt/bower and usage: https://github.com/yeoman/yeoman/wiki/Getting-Started

Main things to edit are:
  • app/scripts/
  • app/scripts/controllers/
  • app/scripts/directives/
  • app/scripts/filters/
  • app/scripts/services/
  • app/styles
  • app/views

Routing

One gotcha is defining routes using $routeProvider. Url's in the document are defined as
<a href='#/path/to/route'>Clicky</a>
Where as the url is defined in the $routeProvider config as
function routeConfig($routeProvider) { $routeProvider. when('/path/to/route', { controller: MyController, templateUrl: 'template.html' })
...

notice this mismatch between the link (pre-ceeding '#') and the url (no '#')

https://github.com/angular-ui/ui-router Provides a way to nest views which seems a lot more powerful then the native routing.

TLS / Http CONNECT handling for proxies

Some brief notes on behaviour.

General Theory
RFC for upgrading HTTP to TLS (Specifically section 5.2)
  http://www.ietf.org/rfc/rfc2817.txt
IEFT draft spec
  http://tools.ietf.org/html/draft-luotonen-web-proxy-tunneling-01

Basic steps (Using sockets / threads):
1) received 'CONNECT host:port HTTP/1.1
2) Open socket to host:port
3) If successful send back a 'HTTP/1.1 Connection Established\n\n" response
4) connect streams of client / and terminal host:port (pass bytes freely between client / server)

Todo:

  • Using SocketChannels / Selectors for non-blocking I/O
  • Testing
    • Performance
    • Unit-testing


Application / Domain specific
nodejs impl and discussion:
  https://groups.google.com/forum/#!topic/nodejs/KDAW_xEwTEg
nodejs and connect:
  https://groups.google.com/forum/#!search/http$20connect/nodejs/MGeOheQQF28/T2VmEjjbn-0J