Package Exports
- ol
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ol) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Let's make it easy and simple !
A simple http server built on top of express. This one makes it easy to create Rest APIs.
Installation :
$ npm install olHow does it work ?
After requiring the module, you just need to specify the routes path and the controllers directory, Assuming you have this project structure:
.
├── app.js
├── routes.json
└── controllers
└── TestControllerTo specify the path to routes file and controllers directory :
var Ol = require('ol');
var ol = Ol({
routes : "./routes.json",
controllers : "/ontrollers"
});The ol object is actually the express app, you just need to make it listen on a specific port :
ol.listen('3000', function () {
console.log(" Listening ... ! ");
});You also can pass the path to a json file to the Ol constructor. This file should contain the path to routes.json and the controllers directory.
params.json :
{
"routes" : "./routes.json",
"controllers" : "/ontrollers"
}app.js :
var Ol = require('ol');
var ol = Ol('./params.json');Example of routes.json:
[
{
"method" : "GET",
"route" : "/",
"controller" : "TestController",
"action" : "sayHi"
},
{
"method" : "POST",
"route" : "/testpost",
"controller" : "TestController",
"action" : "anotherAction"
}
]Example of a controller (TestController)
module.exports = {
sayHi : function (req, res) {
res.json({
foo : bar
});
},
anotherAction : function (req, res) {
res.send(req.params);
}
}