Skip to content

Migrating from 0.3.x to 0.4.x

Jared Hanson edited this page Dec 1, 2013 · 9 revisions

Removed

  • Locomotive#controller controllers are now auto-required

Changed

  • renamed Locomotive#invoke to Locomotive#invokable
  • after filters now run after the response has finished
  • a server.js file is now the recommended way to start a server, replacing lcm server
server.js
var locomotive = require('locomotive')
  , bootable = require('bootable');

// Create a new application and initialize it with *required* support for
// controllers and views.  Move (or remove) these lines at your own peril.
var app = new locomotive.Application();
app.phase(locomotive.boot.controllers(__dirname + '/app/controllers'));
app.phase(locomotive.boot.views());

// Add phases to configure environments, run initializers, draw routes, and
// start an HTTP server.  Additional phases can be inserted as neeeded, which
// is particularly useful if your application handles upgrades from HTTP to
// other protocols such as WebSocket.
app.phase(require('bootable-environment')(__dirname + '/config/environments'));
app.phase(bootable.initializers(__dirname + '/config/initializers'));
app.phase(locomotive.boot.routes(__dirname + '/config/routes'));
app.phase(locomotive.boot.httpServer({ address: '0.0.0.0', port: 3000 }));

// Boot the application.  The phases registered above will be executed
// sequentially, resulting in a fully initialized server that is listening
// for requests.
app.boot(function(err) {
  if (err) {
    console.error(err.message);
    console.error(err.stack);
    return process.exit(-1);
  }
});