{"action":"published","release":{"url":"https://api.github.com/repos/alash3al/HorusJS/releases/1290905","assets_url":"https://api.github.com/repos/alash3al/HorusJS/releases/1290905/assets","upload_url":"https://uploads.github.com/repos/alash3al/HorusJS/releases/1290905/assets{?name}","html_url":"https://github.com/alash3al/HorusJS/releases/tag/v1.0.3","id":1290905,"tag_name":"v1.0.3","target_commitish":"master","name":"Horus.js - v1.0.3","draft":false,"author":{"login":"alash3al","id":3078292,"avatar_url":"https://avatars.githubusercontent.com/u/3078292?v=3","gravatar_id":"","url":"https://api.github.com/users/alash3al","html_url":"https://github.com/alash3al","followers_url":"https://api.github.com/users/alash3al/followers","following_url":"https://api.github.com/users/alash3al/following{/other_user}","gists_url":"https://api.github.com/users/alash3al/gists{/gist_id}","starred_url":"https://api.github.com/users/alash3al/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alash3al/subscriptions","organizations_url":"https://api.github.com/users/alash3al/orgs","repos_url":"https://api.github.com/users/alash3al/repos","events_url":"https://api.github.com/users/alash3al/events{/privacy}","received_events_url":"https://api.github.com/users/alash3al/received_events","type":"User","site_admin":false},"prerelease":false,"created_at":"2015-05-13T09:51:09Z","published_at":"2015-05-13T09:53:08Z","assets":[],"tarball_url":"https://api.github.com/repos/alash3al/HorusJS/tarball/v1.0.3","zipball_url":"https://api.github.com/repos/alash3al/HorusJS/zipball/v1.0.3","body":"### Intro\r\nHorusJS is an advanced lightweight microframework for nodejs, it has a very light router\r\nthat doesn't use any loop to dispatch the matched listener but it just let nodejs it self\r\nto manage it, the first route you write is the first route will be checked .\r\nIt has no complex code, you will use the default `req` and `res` objects in your routes\r\n\r\n### install\r\n`npm install horus.js`\r\n\r\n### Learn by examples\r\n**Example #1**  `basic`\r\n```javascript\r\n\r\nhttp  = require('http')\r\nhorus = require('horus.js')\r\n\r\nhttp.createServer(function(req, res){\r\n\tapp = horus(req, res)\r\n\tapp.run(function(){\r\n\t\tapp.router.on('/', function(req, res){\r\n\t\t\tres.end('we are in the index')\r\n\t\t})\r\n\t\tapp.router.on('GET /hello', function(req, res){\r\n\t\t\tres.end('Hello World')\r\n\t\t})\r\n\t\t// chaining ?\r\n\t\t// if you don't specify method it will run for any request method\r\n\t\t.on('GET /hi/([a-z]+)', function(req, res, name){\r\n\t\t\tres.end('Hi ' + name + ' !')\r\n\t\t})\r\n\t\t.on('GET|POST /hi/([a-z]+)/([0-9]+)', function(req, res, name, number){\r\n\t\t\tres.end('Hi ' + name + ', age: ' + number + ' ?!')\r\n\t\t})\r\n\t\t// group of routes for the same prefix ?\r\n\t\t.group('/parent', function(req, res){\r\n\t\t\t// instead of app.router, just use 'this'\r\n\t\t\tthis.on('/child1', function(){\r\n\t\t\t\tres.end('/parent/child1')\r\n\t\t\t})\r\n\t\t\tthis.on('/child2', function(){\r\n\t\t\t\tres.end('/parent/child2')\r\n\t\t\t})\r\n\t\t})\r\n\t\t// if nodejs reached here, send 404 error for any path\r\n\t\t// because it didn't find any matched route\r\n\t\t.on('(.+)', function(req, res, path){\r\n\t\t\tres.end('<h1> 404 not found</h1><p>We cannot find any matched object for \"'+ req.hostname + '/' + path +'\" </p>')\r\n\t\t})\r\n\t})\r\n})\r\nhttp.listen(8080)\r\n\r\n```\r\n\r\n**Example #2**  `vhosts`\r\n```javascript\r\n\r\nhttp  = require('http')\r\nhorus = require('horus.js')\r\n\r\nhttp.createServer(function(req, res){\r\n\tapp = horus(req, res)\r\n\tapp.run(function(){\r\n\t\t// vhost routing\r\n\t\t// i'm using localtest.me for testing\r\n\t\t// it is a free service alternative to 'localhost'\r\n\t\t// that will redirect any request to your local machine\r\n\t\t// on port '80'\r\n\t\tapp.router.vhost('user-([0-9]+).localtest.me', function(id)\r\n\t\t{\r\n\t\t\t// this: referers to app.router\r\n\t\t\tthis.on('/', function(req, res){\r\n\t\t\t\tres.end(\"sub-domain, uid: \" + id)\r\n\t\t\t})\r\n\t\t})\r\n\r\n\t\tapp.router.vhost('localtest.me', function()\r\n\t\t{\r\n\t\t\tthis.on('/', function(req, res){\r\n\t\t\t\tres.end('Hello World !')\r\n\t\t\t})\r\n\t\t})\r\n\r\n\t\t// if nodejs reached here, send 404 error\r\n\t\t// because it didn't find any matched route\r\n\t\t.on('(.+)', function(req, res, path){\r\n\t\t\tres.end('<h1> 404 not found</h1><p>We cannot find any matched object for \"'+ req.hostname + '/' + path +'\" </p>')\r\n\t\t})\r\n\t})\r\n})\r\nhttp.listen(80)\r\n\r\n```\r\n\r\n**Example #3**  `middlewares/layers`\r\n> layers are just callbacks that will be executed before processing the request  \r\n\r\n```javascript\r\n\r\nhttp  = require('http')\r\nhorus = require('horus.js')\r\n\r\nhttp.createServer(function(req, res){\r\n\tapp = horus(req, res)\r\n\tapp.layers.bind(function(req, res){\r\n\t\tconsole.log('layer #1')\r\n\t}).bind(function(req, res){\r\n\t\tconsole.log('layer #2')\r\n\t}).bind(function(){\r\n\t\tres.end('this will end the response and ignore any other event')\r\n\t})\r\n\tapp.run(function(){\r\n\t\tapp.router.on('/', function(){\r\n\t\t\tres.end('Hello World')\r\n\t\t})\r\n\t})\r\n})\r\nhttp.listen(80)\r\n\r\n```\r\n\r\n### other properties\r\n```javascript\r\n// horus adds new properties to request object\r\n// req.path: the current path '/path/?query' > \"/path/\"\r\n// req.hostname: the current hostname 'hostname:port' > \"hostname\"\r\n```\r\n"}}