Skip to content

Starting Aeolus

Mathias Quintero edited this page Mar 18, 2016 · 3 revisions

Staring it

To use kickstart Aeolus you simply have to call the function createServer with the port number you want it to listen to.

We recommend having this code:

var Aeolus = require('Aeolus');

var port = process.env.PORT || 8080;

Aeolus.createServer(port);

More Options

Other folders

Aeolus will by default listen to the "/methods" and "/www" folders for your API and public page. But you can give Aeolus another path to listen to instead with the functions .methods and .www. For Example:

Aeolus.methods("/api");  // API Methods are now in the /api folder
Aeolus.methods("/html"); // Web page is now in the /html folder

Authentification

You can tell Aeolus how authentication works in your site by providing an authentication function. This function would take a username and a password and callback a function with a boolean value (representing if the auth info is valid). So that all methods marked as needing Authentication will prompt the user for a password.

You can enter this function by calling auth. For Example:

Aeolus.auth(function(name,pass,callback) {
  var valid = name === "root" && pass === "alpine";
  callback(valid);
});

Error handling

One of the many features of the Framework is that you can also specify what will happen when there are any errors, when catching exceptions, handling resources that couldn't be found, etc.

Aeolus provides two important error handlers:

The .onError handler that will be fired up when there Aeolus couldn't find what the user was looking for or an internal error occurred and .unauthorised that will be called when a user tried to access something without authorisation. For example:

Aeolus.onError(function(request,response,message) {
  if (message.indexOf("TypeError") >= 0) {
    response.respondPlainText("Internal Error",501);
  } else {
    response.redirect("/404");
  }
});

And the .unauthorised handler that gets called when the auth information entered by the user is incorrect!

Aeolus.unauthorised(function(request,response) {
  response.promptForPassword("Please enter a password");
});
Clone this wiki locally