Skip to content
Victorma Perez Colado edited this page May 5, 2017 · 6 revisions

Deployment can be quite easy if you follow these steps.

Some dependencies

Before we start running some scripts you will need to have installed some dependencies.

MongoDB

Why do you need MongoDB?

Because it serves as storage for some of the services provided by the REST API. The roles, resources and permissions are stored directly into MongoDB using node_acl, which provides Access Control List functionality. Mongoose stores the registered users and applications. It provides a schema-based solution to model the application data.

Start by downloading the current stable MongoDB release and reading through the MongoDB Node.js getting started guide.

You might also want to check out the Mongoose documentation if you're going to change the source code.

Redis

Used as a JWT cache to be able to invalidate tokens at will. JWT tokens are automatically generated using a secret key, stored in Redis and sent to the user when a login request is performed. Every protected route must have an Oauth 2.0 Authorization header with the JWT token.

Download Redis and read through its documentation for a better understanding of what's going on under the hood. If you're going to work with the source code you might be interested in checking out the redis npm module that we use as a cache to store and retrieve JWT tokens.

NodeJS

Used as the base technology of this module. Go to its download page and follow the steps described there. This should have installed also the Node Package Manager (npm) needed to continue with the next steps.

Deployment commands

Now that you have MongoDB and Redis, you should launch their daemons before continuing with the next steps.

Assuming you already have forked the repository on http://github.com/e-ucm/a2, you will need to open a console inside the forked repository folder and run some commands.

Take a look at the available scripts for a better understanding of the next commands.

Install

npm install

Will automatically download and install all the aditional dependencies required by this module so that we can run it correctly.

Bower is also required. To install:

npm install -g bower

bower install

Setup

  • Linux npm run fast-setup
  • Windows npm run fast-setup-win

fast-setup will do several things:

  1. Create config.js and config-test.js files with this default values. These files are required for launching and running tests, more info. can be found here.
  2. Register a root user in the database with the admin role. This is necessary because we need to have at least one admin in our database for a correct usage.

You may also be interested into npm run setup for a CLI interactive step by step configuration of the default values. Note that this script will also clean the whole users database before finishing.

If you are interested in a more advanced configuration process, you can manually create two files (config.js and config-test.js) with the following content. Do this only if you know what you are configuring since this can create conflicts between the values of the two files, which will result into strange behaviors when launching the application or running the tests.

Test

  • Linux npm test
  • Windows npm run test-win

It's a good practice to run this command before deploying the service. If every test has passed successfully you can follow with the next step (starting).

If you want to contribute with pull requests you should always run this command prior to creating the pull request to assure that your changes haven't broken any tests. Travis will automatically do this for you when the pull request is created. If the tests are not passed successfully the pull request will not be considered ready and won't be accepted.

Start

npm start

Starts the service, check it out at http://localhost:3000/ (default address). You can log in as root/root and create new roles, edit registered user profiles, assign roles to users and create new applications.

Congratulations, you've finished deploying a2 module!

Clone this wiki locally