beanpoll-http

0.0.10 • Public • Published

Features

  • expose your beanpole routes over HTTP
  • easy to specify HTTP Middleware

Plugins

  • http.gateway exposes your beanpole routes over HTTP.
  • http.server starts up the http server.
  • http.middleware middleware for http specific routes

Usage

Basic Configuration:

//sets add a require path to the app

var loader = require('beanie');


loader.params({
	publicDir: __dirname + "/public"
	http: {
		port: 8080
	}
});

loader.
require('beanpoll-http').
load();

Middleware

Basic Auth Middleware

router.on({
	
	/**
	 */
	
	'pull basic/auth/user/pass -> secret/route': function() {
		return "authorized!";
	},
	
	
	/**
	 */
	
	'pull secret/route': function(request) {

		function login(user, pass, callback) {

			if(user == 'user' && pass == 'pass') return callback(false, { user: 'user' });
			
			callback('wrong user / pass');
		}
		
		request.forward('basic/auth', { login: login }, function(response) {

			request.end('authorized!');
		})
	}
});

Session Middleware

router.on({
	
	/**
	 */
	
	'pull session -> account': function(request) {
		
		//should be "test" on next call
		console.log(request.session.data.username);
		
		request.session.data.username = 'test';
	},
	
})

Readme

Keywords

none

Package Sidebar

Install

npm i beanpoll-http

Weekly Downloads

5

Version

0.0.10

License

none

Last publish

Collaborators

  • architectd