Hide
Search Results

Basic Configuring of Applications

Time Estimate: 10 minutes

Difficulty Level: Beginning

Summary

This example shows how to configure a mojit and the routing for your application.

Implementation Notes

The application.json file is used to specify the mojits that your application can use. The example application.json below specifies that the application use the mojit SimpleMojit.

[
  {
    "settings": [ "master" ],
    "specs": {
      "simple": {
        "type": "SimpleMojit"
      }
    }
  }
]

The routing configuration for Mojito applications is contained in routes.json. In this example routes.json, the Mojito server is told to call the index method in the controller when HTTP GET called on the root path.

[
  {
    "settings": [ "master" ],
    "simple": {
      "verbs": ["get"],
      "path": "/",
      "call": "simple.index"
    }
  }
]

The index method is a canned method in the controller when you create a mojit. To learn how to create templates that get data from the controller, see Creating a Simple View with Handlebars.

Setting Up this Example

To set up and run simple_config:

  1. Create your application.

    $ mojito create app simple_config

  2. Change to the application directory.

  3. Create your mojit.

    $ mojito create mojit SimpleMojit

  4. To specify that your application use SimpleMojit, replace the code in application.json with the following:

    [
      {
        "settings": [ "master" ],
        "specs": {
          "simple": {
            "type": "SimpleMojit"
          }
        }
      }
    ]
    
  5. To configure routing, replace the code in routes.json with the following:

    [
      {
        "settings": [ "master" ],
        "simple": {
          "verbs": ["get"],
          "path": "/",
          "call": "simple.index"
        }
      }
    ]
    
  6. From the application directory, run the server.

    $ mojito start

  7. To view your application, go to the URL:

    http://localhost:8666