Beginning AngularJS

(WallPaper) #1
Chapter 10

Deployment Considerations


Application deployment is an increasingly complex and multi-faceted topic. There is no quick answer as to how to
approach it, because every application is unique. However, there are a number of best practices, techniques, and
tools available that you should consider integrating into your workflow and build process. While the title of this
chapter is Deployment Considerations, much of what is covered is applicable at the outset of a project right through to
deployment and beyond.
In this chapter, we will take a brief look at some topics that are very likely to make their way onto your developer
radar, once you have been using AngularJS for a while; topics that we don’t really have time or space to cover in much
detail in this book, but nonetheless they deserve a mention. You won’t find much in-depth coverage here, as my aim
is merely to introduce you to a sampling of the activities and issues that AngularJS developers often factor into their
projects and workflows.


Configuration


We often want our AngularJS apps to run with different settings or configurations. For example, many web applications
need to connect to a service of some kind so that they can interact with data sourced from the back-end. It is quite
common to use one URL for the development server and another URL for the production server. In a scenario like
this, we need to find a way to provide for configuration within our applications. Quite possibly the easiest way to use
configuration within AngularJS is to set a constant with an object, which is the approach we will look at next.
It isn’t uncommon for developers to create a separate module specifically for configuration. The code in
Listing 10-1 below lives in a file named app.config.js.


Listing 10-1. app.config.js: setting up a constant


angular.module('app.config',[])
.constant('myConfig', {
'apiUrl': 'http://localhost:8080',
'adminEmail': '[email protected]'
});


This module doesn’t do much more than set up a constant called myConfig, as declared through the constant()
methods first argument. The key point to observe here is that the second argument to the constant method is an
object containing our configuration data; this object has two properties. We have one property containing the URL
that our app should be using to communicate with the back-end and another property containing an email address
the app can use to determine to whom to send support email.

Free download pdf