Yahoo! Mojito: Part 1 – Hello World!

Yahoo! Mojito:: Part 1 - Hello World:: Artifacts

2. Customize port and map at “/”

Now that we have the application running, let’s make two changes – make it run on port 80 and ensure that we don’t make life of our users hell by asking them to remember such a long URL.

application.json has a configuration named appPort with default value of 8666 unless specified otherwise. So, let’s specify the otherwise. Update the contents to as follows:

[
    {
        "settings": [ "master" ],
        "appPort": 80,
        "specs": {
            "hello_mojit": {
                "type": "HelloMojit"
            }
        }
    }
]

And then, do a

$ sudo mojito start

The sudo is required because the application will not run on port 80, and most Unix/Linux systems require admin/root privileges to run a server on ports below 1024.

Now, you can browse to http://localhost/@HelloMojit/index.

The next big thing to have the same content available at http://localhost rather than the otherwise obscure URL. The routing configuration resides in a separate routes.json file.

Why a separate file? Well, it definitely makes a sense to segregate the mojit-list and their access points.

So, let’s update the routes.json file with the following content:

[{
    "settings": [ "master" ],
    "root": {
        "path": "/",
        "verbs": [ "GET" ],
        "call": "hello_mojit.index"
    }
}]

The content reads that for settings “master”, if anyone access the path "/" (root) using the HTTP GET method, call the action index of hello_mojit registered in application.json.

Restart the server… and now you are ready to browse to http://localhost.

Having said that, if you try to browser to the earlier URL, you should get a 404. Mojito application is pre-configured to ensure that if you do have at least one route registered, direct access to any mojit will not be allowed – ensures accidental access.


Notice: This work is licensed under a BY-NC-SA. Permalink: Yahoo! Mojito: Part 1 – Hello World!

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

*