Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

em-rest

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

em-rest - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

lib/Responder.js

162

lib/index.js

@@ -12,3 +12,4 @@

var JSONRenderer = require( "./JSONRenderer" )
, HTMLRenderer = require( "./HTMLRenderer" );
, HTMLRenderer = require( "./HTMLRenderer" )
, Responder = require( "./Responder" );

@@ -22,84 +23,6 @@

, methods: [ "put", "get", "options", "head", "post", "patch", "delete" ]
, status: {
100: "Continue"
, 101: "Switching Protocols"
, 102: "Processing"
, 200: "OK"
, 201: "Created"
, 202: "Accepted"
, 203: "Non-Authoritative Information"
, 204: "No Content"
, 205: "Reset Content"
, 204: "response"
, 206: "Partial Content"
, 207: "Multi-Status"
, 208: "Already Reported"
, 226: "IM Used"
, 300: "Multiple Choices"
, 301: "Moved Permanently"
, 302: "Found"
, 303: "See Other"
, 304: "Not Modified"
, 305: "Use Proxy"
, 306: "Switch Proxy"
, 307: "Temporary Redirect"
, 308: "Permanent Redirect"
, 400: "Bad Request"
, 401: "Unauthorized"
, 403: "Forbidden"
, 402: "Payment Required"
, 403: "Forbidden"
, 404: "Not Found"
, 405: "Method Not Allowed"
, 406: "Not Acceptable"
, 407: "Proxy Authentication Required"
, 408: "Request Timeout"
, 409: "Conflict"
, 410: "Gone"
, 411: "Length Required"
, 412: "Precondition Failed"
, 413: "Request Entity Too Large"
, 414: "Request-URI Too Long"
, 415: "Unsupported Media Type"
, 416: "Requested Range Not Satisfiable"
, 417: "Expectation Failed"
, 418: "I'm a teapot"
, 420: "Enhance Your Calm"
, 422: "Unprocessable Entity"
, 423: "Locked"
, 424: "Method Failure"
, 425: "Unordered Collection"
, 426: "Upgrade Required"
, 428: "Precondition Required"
, 429: "Too Many Requests"
, 431: "Request Header Fields Too Large"
, 444: "No Response"
, 451: "Unavailable For Legal Reasons"
, 494: "Request Header Too Large"
, 495: "Cert Error"
, 496: "No Cert"
, 497: "HTTP to HTTPS"
, 499: "Client Closed Request"
, 500: "Internal Server Error"
, 501: "Not Implemented"
, 502: "Bad Gateway"
, 503: "Service Unavailable"
, 504: "Gateway Timeout"
, 505: "HTTP Version Not Supported"
, 506: "Variant Also Negotiates"
, 507: "Insufficient Storage "
, 508: "Loop Detected"
, 509: "Bandwidth Limit Exceeded"
, 510: "Not Extended"
, 511: "Network Authentication Required"
, 598: "Network read timeout error"
, 599: "Network connect timeout error"
}
, controllers: {}
, renderers: {}
, contentTypes: []
, contentTypeReg: new RegExp( "a{99}", "gi" )
, defaultRenderer: null

@@ -202,3 +125,11 @@

, addRenderer: function( contentType, renderer, isDefault ){
if ( isDefault ) this.defaultRenderer = renderer;
if ( isDefault ) {
if ( this.defaultRenderer ) this.defaultRenderer.isDefault = false;
this.defaultRenderer = renderer;
renderer.isDefault = true;
}
this.contentTypes.push( contentType );
this.contentTypeReg = new RegExp( "(" + this.contentTypes.join( "|" ) + ")", "gi" );
this.renderers[ contentType.toLowerCase() ] = renderer;

@@ -209,18 +140,9 @@ }

, contentTypeNegation: function( request, response, callback ){
var accept = request.getHeader( "accept", true ), contentType;
if ( accept ){
for( var i = 0, l = accept.length; i < l; i++ ){
contentType = accept[ i ].key.toLowerCase() + "/" + accept[ i ].value.toLowerCase();
if ( contentType === "*/*" ) break;
else if ( this.renderers[ contentType ] ){
callback( this.renderers[ contentType ], false );
return;
}
}
}
callback( this.defaultRenderer, true );
, contentTypeNegation: function( request, response ){
var result;
if ( result = this.contentTypeReg.exec( request.getHeader( "accept" ) || "" ) ){
this.contentTypeReg.lastIndex = 0;
return this.renderers[ result[ 1 ].toLowerCase() ];
}
}

@@ -259,2 +181,6 @@

, request: function( request, response, next ){

@@ -273,36 +199,12 @@ var parts = request.pathname.split( "/" ).filter( function( p ){ return p.length > 0; } )

// supported method
if ( this.methods.indexOf( request.method ) === -1 ) response.render( null, {}, 501 );
if ( this.methods.indexOf( request.method ) === -1 ) response.send( 501 );
else {
// get renderer
this.contentTypeNegation( request, response, function( renderer, isDefaultRenderer ){
// attach render hook
response.render = function( data, headers, statusCode ){
if ( !isDefaultRenderer ) {
if ( !statusCode ) statusCode = 200;
if ( !data ) data = {};
renderer.render( data, request, response, function( renderedData ){
response.sendUncompressed( renderedData, headers, statusCode );
} );
}
else response.send( "", {}, 406 );
}.bind( this );
// method supported by controller?
if ( typeof controller[ request.method ] === "function" ){
// invoke the controller
controller[ request.method ]( request, response, next );
}
else {
var allow = [ "options" ].concat( this.methods ).filter( function( method ){
return typeof controller[ method ] === "function";
} ).join( ", " ).toUpperCase();
response.render( null, { Allow: allow }, request.method === "options" ? 200 : 405 );
}
}.bind( this ) );
new Responder( {
request : request
, response : response
, next : next
, parent : this
, controller : controller
} );
}

@@ -309,0 +211,0 @@ }

{
"name": "em-rest"
, "description": "rest service middleware for ee-webservice"
, "version": "0.1.4"
, "homepage": "https://github.com/eventEmitter/em-rest"
, "author": "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"
"name" : "em-rest"
, "description" : "rest service middleware for ee-webservice"
, "version" : "0.1.5"
, "homepage" : "https://github.com/eventEmitter/em-rest"
, "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"
, "licence" : "mit"
, "os" : "linux"
, "repository": {
"url": "https://github.com/eventEmitter/em-rest"
"url" : "https://github.com/eventEmitter/em-rest.git"
, "type" : "git"
}
, "engines": {
"node": "*"
"node" : "*"
}
, "bugs": {
"url": "https://github.com/eventEmitter/em-rest/issues"
"url" : "https://github.com/eventEmitter/em-rest/issues"
}
, "dependencies": {
"ee-class": "*"
, "ee-event": "*"
, "ee-log": "*"
, "ee-waiter": "*"
"ee-class" : "*"
, "ee-event" : "*"
, "ee-log" : "*"
, "ee-types" : "*"
, "ee-waiter" : "*"
}

@@ -22,0 +26,0 @@ , "devDependencies": {}

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc