Features
- Auto Routes [simple & Advanced]
- Handle Response Headers & codes
- Auto Configer Request Cookies & Query Strings
- Auto Detect & Configer User Session
- Auto Caching Files in Memory
- MD5 Hash Function
Installation
npm install isite --save
Using
var isite = require('isite')
var site = isite()
site.run()
Advanced Using
var isite = require('isite')
var site = isite({
port:8080 ,
dir:__dirname + '/site_files'
})
site.run()
Routes
Easy and Auto Site Routing
site.addRoute({name: '/js/jquery.js',path: site.dir + '/js/jquery.min.js'});
site.addRoute({name: '/js/bootstrap.js',path: site.dir + '/js/bootstrap.min.js'});
site.addRoute({name: '/css/bootstrap.css',path: site.dir + '/css/bootstrap.min.css'});
site.addRoute({name: '/',path: site.dir + '/html/index.html'});
site.addRoute({name: '/api',path: site.dir + '/json/employees.json' , method:'POST'});
Advanced Site Routing
site.addRoute({
name: '/',
callback: function (req, res) {
res.setHeader('Content-type', 'text/html');
res.writeHead(200);
site.html('index', function (err, content) {
res.end(content);
});
}
});
site.addRoute({
name: '/api',
method: 'POST',
callback: function (req, res) {
res.setHeader('Content-type', 'application/json');
res.writeHead(200);
site.json('index', function (err, content) {
res.end(content);
});
}
});
Cookies
site.get('/api/set' , function(req , res){
req.cookie.set('id' , 'userid')
res.end('cookie set ok !!')
})
site.get('/api/get' , function(req , res){
res.end(' id : ' + req.cookie.get('id'))
})
Sessions
site.get('/login', function(req, res) {
req.session.set('username', 'amr barakat')
res.end('loged ok !! ')
})
site.get('/userInfo', function(req, res) {
var userName = req.session.get('username')
res.end(userName)
})
More