Skip to content

Commit

Permalink
licence, bugfixing, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael van der Weg committed Jun 20, 2013
1 parent e0474fa commit a6e4904
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,5 @@ logs
results

npm-debug.log

node_modules
16 changes: 16 additions & 0 deletions LICENCE
@@ -0,0 +1,16 @@
Copyright (C) 2013 Michael van der Weg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions index.js
@@ -0,0 +1,4 @@



module.exports = require( "./lib/Webservice" );
58 changes: 58 additions & 0 deletions lib/Webservice.js
@@ -0,0 +1,58 @@



var Class = require( "ee-class" )
, Events = require( "ee-event" )
, log = require( "ee-log" )
, Webserver = require( "ee-webserver" );




module.exports = new Class( {
inherits: Events

, "static Webserver": Webserver


, middleware: []


, init: function( options ){
this.webserver = new Webserver( options.webserver );
this.webserver.on( "request", this.handleRequest.bind( this ) );
}


, handleRequest: function( request, response ){
this.nextRequest( request, response );
}


, nextRequest: function( request, response ){
var index = 0
, next = function( err ){
if ( this.middleware.length > index ) {
index++;
this.middleware[ index - 1 ].request( request, response, next, this.middleware.length === index );
}
else response.send();
}.bind( this );

next();
}


, listen: function( callback ){
this.webserver.listen( function(){
this.emit( "listening" );
if ( typeof callback === "function" ) callback();
}.bind( this ) );
}



, use: function( middleware ){
this.middleware.push( middleware );
}
} );
26 changes: 26 additions & 0 deletions package.json
@@ -0,0 +1,26 @@
{
"name": "ee-webservice"
, "description": "A framework for Webservices"
, "version": "0.1.0"
, "homepage": "https://github.com/eventEmitter/ee-webservice"
, "author": "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"
, "repository": {
"url": "https://github.com/eventEmitter/ee-webservice"
}
, "engines": {
"node": "*"
}
, "bugs": {
"url": "https://github.com/eventEmitter/ee-webservice/issues"
}
, "dependencies": {
"ee-class": "*"
, "ee-event": "*"
, "ee-log": "*"
, "ee-argv": "*"
, "ee-waiter": "*"
, "ee-webserver": "*"
}
, "devDependencies": {}
, "optionalDependencies": {}
}
27 changes: 27 additions & 0 deletions test.js
@@ -0,0 +1,27 @@



var Webservice = require( "./" )
, Mutlilang = require( "../em-multilang" );



var service = new Webservice( {
webserver: {
http: {
interface: Webservice.Webserver.IF_ANY
, port: 12001
}
}
} );


service.use( new Mutlilang( {
defaultLanguage: "en"
, languages: [ "en", "fr", "it", "de" ]
, externalRedirect: false
} ) );


service.listen();

0 comments on commit a6e4904

Please sign in to comment.