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

connect

Package Overview
Dependencies
Maintainers
0
Versions
234
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

lib/connect/._utils.js

2

._index.js

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR�����"�"com.macromates.caret{
column = 42;
line = 1;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR����"�"com.macromates.caret{
column = 19;
line = 3;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR����#�#com.macromates.caret{
column = 23;
line = 11;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR����#�#com.macromates.caret{
column = 24;
line = 9;
line = 11;
}

@@ -0,1 +1,2 @@

/*!

@@ -10,22 +11,26 @@ * Ext JS Connect

*/
exports.version = '0.5.2';
exports.version = '0.5.3';
/**
* Module dependencies.
*/
var sys = require('sys'),
fs = require('fs'),
Url = require('url'),
Path = require('path'),
http = require('http'),
assert = require('assert');
// Temp patch to make connect work better in the v0.3.x branch of node
var fs = require('fs')
, http = require('http')
, utils = require('./utils')
, assert = require('assert');
/**
* COMPAT: 0.3.x support
*/
try {
var CONSTANTS = require('constants');
Object.keys(CONSTANTS).forEach(function (key) {
process[key] = CONSTANTS[key];
var consts = require('constants');
Object.keys(consts).forEach(function (key) {
process[key] = consts[key];
});
} catch (err) {
// Ignore
}

@@ -35,10 +40,8 @@

* Default env for those who do not use spark.
*
* @type Object
*/
process.connectEnv = process.sparkEnv || {
name: process.env.NODE_ENV || 'development',
port: 3000,
host: null
name: process.env.NODE_ENV || 'development'
, port: 3000
, host: null
};

@@ -66,16 +69,19 @@

var Server = exports.Server = function Server(layers) {
this.stack = [];
this.stack = [];
// Stack layers
layers.forEach(function(layer){
this.use("/", layer);
}, this);
// Stack layers
layers.forEach(function(layer){
this.use("/", layer);
}, this);
// Set up the request handler using the parent's constructor
http.Server.call(this, this.handle);
// Set up the request handler using the parent's constructor
http.Server.call(this, this.handle);
};
// Server is a subclass of http.Server
sys.inherits(Server, http.Server);
/**
* Inherit from `http.Server.prototype`.
*/
Server.prototype.__proto__ = http.Server.prototype;
/**

@@ -91,49 +97,48 @@ * Stack the given middleware `handle` to the given `route`.

Server.prototype.use = function(route, handle){
if (typeof route !== 'string') {
handle = route;
route = '/';
}
if (typeof route !== 'string') {
handle = route;
route = '/';
}
// Allow for more than one handle function to be added at a time
if (arguments.length > 2) {
Array.prototype.slice.call(arguments, 1).forEach(function (handle) {
this.use(route, handle);
}, this);
return this;
}
// Allow for more than one handle function to be added at a time
if (arguments.length > 2) {
Array.prototype.slice.call(arguments, 1).forEach(function (handle) {
this.use(route, handle);
}, this);
return this;
}
// Wrap sub-apps
if (handle instanceof Server) {
var server = handle;
server.route = route;
handle = function(req, res, next) {
server.handle(req, res, next);
};
}
// Wrap sub-apps
if (handle instanceof Server) {
var server = handle;
server.route = route;
handle = function(req, res, next) {
server.handle(req, res, next);
};
}
// Wrap vanilla http.Server instances too
// Maybe later we'll handle 404 and 500 responses and pass them to next()
// But for now, this is the end of the chain
if (handle instanceof http.Server) {
handle = handle.listeners('request')[0];
}
// Wrap vanilla http.Server instances too
// Maybe later we'll handle 404 and 500 responses and pass them to next()
// But for now, this is the end of the chain
if (handle instanceof http.Server) {
handle = handle.listeners('request')[0];
}
// Validate the input
if (!(typeof route === 'string' && typeof handle === 'function')) {
throw new Error("Each layer must have a route and a handle function");
}
// Validate the input
if (!(typeof route === 'string' && typeof handle === 'function')) {
throw new Error("Each layer must have a route and a handle function");
}
// Normalize route to not trail with slash
if (route[route.length - 1] === '/') {
route = route.substr(0, route.length - 1);
}
// Normalize route to not trail with slash
if (route[route.length - 1] === '/') {
route = route.substr(0, route.length - 1);
}
// Add the route, handle pair to the stack
this.stack.push({ route: route, handle: handle });
// Add the route, handle pair to the stack
this.stack.push({ route: route, handle: handle });
// Allow chaining
return this;
// Allow chaining
return this;
};
/**

@@ -151,6 +156,6 @@ * Listen on the given `port` number,

Server.prototype.listen = function(port, host) {
arguments[0] = port || process.connectEnv.port || 3000;
arguments[1] = host || process.connectEnv.host;
http.Server.prototype.listen.apply(this, arguments);
return this;
arguments[0] = port || process.connectEnv.port || 3000;
arguments[1] = host || process.connectEnv.host;
http.Server.prototype.listen.apply(this, arguments);
return this;
};

@@ -166,87 +171,86 @@

Server.prototype.handle = function(req, res, outerNext) {
var writeHead = res.writeHead,
removed = "",
stack = this.stack,
index = 0;
var writeHead = res.writeHead
, removed = ""
, stack = this.stack
, index = 0;
function next(err) {
// Put the prefix back on if it was removed
req.url = req.originalUrl = removed + req.url;
removed = "";
function next(err) {
// Put the prefix back on if it was removed
req.url = req.originalUrl = removed + req.url;
removed = "";
var layer = stack[index++];
var layer = stack[index++];
// If we reached the end of the chain...
if (!layer) {
// ... and we're part of a bigger chain then forward to it.
if (outerNext) {
outerNext(err);
return;
}
// Otherwise send a proper error message to the browser.
if (err) {
var msg = process.connectEnv.name === 'production'
? 'Internal Server Error'
: err.stack || err.toString();
if (process.connectEnv.name !== 'test') {
sys.error(err.stack || err.toString());
}
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end(msg);
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Cannot ' + req.method + ' ' + req.url);
}
return;
// If we reached the end of the chain...
if (!layer) {
// ... and we're part of a bigger chain then forward to it.
if (outerNext) {
outerNext(err);
return;
}
// Otherwise send a proper error message to the browser.
if (err) {
var msg = process.connectEnv.name === 'production'
? 'Internal Server Error'
: err.stack || err.toString();
if (process.connectEnv.name !== 'test') {
console.error(err.stack || err.toString());
}
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end(msg);
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Cannot ' + req.method + ' ' + req.url);
}
return;
}
try {
try {
var path = utils.pathname(req.url);
if (path === undefined) path = '/';
var pathname = Url.parse(req.url).pathname;
if (pathname === undefined) pathname = '/';
// Skip this layer if the route doesn't match.
if (path.indexOf(layer.route) !== 0) {
next(err);
return;
}
// Skip this layer if the route doesn't match.
if (pathname.indexOf(layer.route) !== 0) {
next(err);
return;
}
var nextChar = path[layer.route.length];
if (nextChar && nextChar !== '/' && nextChar !== '.') {
next(err);
return;
}
var nextChar = pathname[layer.route.length];
if (nextChar && nextChar !== '/' && nextChar !== '.') {
next(err);
return;
}
// Call the layer handler
// Trim off the part of the url that matches the route
removed = layer.route;
req.url = req.url.substr(removed.length);
// Call the layer handler
// Trim off the part of the url that matches the route
removed = layer.route;
req.url = req.url.substr(removed.length);
// Ensure leading slash
if (req.url[0] !== "/") {
req.url = "/" + req.url;
}
// Ensure leading slash
if (req.url[0] !== "/") {
req.url = "/" + req.url;
}
var arity = layer.handle.length;
if (err) {
if (arity === 4) {
layer.handle(err, req, res, next);
} else {
next(err);
}
} else if (arity < 4) {
layer.handle(req, res, next);
} else {
next();
}
} catch (e) {
if (e instanceof assert.AssertionError) {
sys.error(e.stack, '\n');
next(e);
} else {
next(e);
}
var arity = layer.handle.length;
if (err) {
if (arity === 4) {
layer.handle(err, req, res, next);
} else {
next(err);
}
} else if (arity < 4) {
layer.handle(req, res, next);
} else {
next();
}
} catch (e) {
if (e instanceof assert.AssertionError) {
console.error(e.stack + '\n');
next(e);
} else {
next(e);
}
}
next();
}
next();
};

@@ -264,6 +268,5 @@

exports.createServer = function() {
return new Server(Array.prototype.slice.call(arguments));
return new Server(Array.prototype.slice.call(arguments));
};
/**

@@ -280,8 +283,8 @@ * Auto-load getters.

fs.readdirSync(__dirname + '/middleware').forEach(function(filename){
if (/\.js$/.test(filename)) {
var name = filename.substr(0, filename.lastIndexOf('.'));
Object.defineProperty(exports.middleware, name, { get: function(){
return require('./middleware/' + name);
}});
}
if (/\.js$/.test(filename)) {
var name = filename.substr(0, filename.lastIndexOf('.'));
Object.defineProperty(exports.middleware, name, { get: function(){
return require('./middleware/' + name);
}});
}
});

@@ -300,2 +303,1 @@

exports.utils = require('./utils');

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���!�!com.macromates.caret{
Mac OS X  2��ATTR����"�"com.macromates.caret{
column = 0;
line = 7;
line = 24;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR����#�#com.macromates.caret{
column = 34;
line = 67;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��!�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR��#��#�#com.macromates.caret{
column = 21;
line = 45;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR��&��"�"com.macromates.caret{
column = 8;
line = 51;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��(�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR��*��#�#com.macromates.caret{
column = 62;
line = 66;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��,�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��.�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���!�!com.macromates.caret{
Mac OS X  2��ATTR��0��!�!com.macromates.caret{
column = 0;
line = 1;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��2�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��4�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���$�$com.macromates.caret{
Mac OS X  2��ATTR��6��$�$com.macromates.caret{
column = 19;
line = 128;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��8�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,1 +0,1 @@

Mac OS X  2��ATTRXM��� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��:�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
column = 0;
line = 176;
Mac OS X  2��ATTR��<��$�$com.macromates.caret{
column = 10;
line = 263;
}

@@ -1,1 +0,4 @@

Mac OS X  2��ATTRXM���!�!com.macromates.caretx���R������<[3 k�@Nf^*�[ ���
Mac OS X  2��ATTR��?��"�"com.macromates.caret{
column = 0;
line = 99;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR��A��"�"com.macromates.caret{
column = 0;
line = 67;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR��E��#�#com.macromates.caret{
column = 41;
line = 30;
}

@@ -98,4 +98,4 @@

var sessionID = base + "." + hash(base);
req.session = new Session(req, sessionID);
req.sessionID = sessionID;
req.session = new Session(req);
};

@@ -102,0 +102,0 @@

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���"�"com.macromates.caret{
Mac OS X  2��ATTR��G��"�"com.macromates.caret{
column = 0;
line = 40;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
Mac OS X  2��ATTR��I��#�#com.macromates.caret{
column = 60;
line = 23;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTRXM���#�#com.macromates.caret{
column = 36;
line = 24;
Mac OS X  2��ATTR��K��"�"com.macromates.caret{
column = 2;
line = 28;
}

@@ -20,8 +20,2 @@

/**
* Default browser cache maxAge of one year.
*/
const MAX_AGE = 31557600000;
/**
* File buffer cache.

@@ -38,3 +32,3 @@ */

* - `root` Root path from which to serve static files.
* - `maxAge` Browser cache maxAge in milliseconds
* - `maxAge` Browser cache maxAge in milliseconds, defaults to 0
* - `cache` When true cache files in memory indefinitely,

@@ -55,3 +49,3 @@ * until invalidated by a conditional GET request.

root = options;
maxAge = MAX_AGE;
maxAge = 0;
} else {

@@ -63,3 +57,3 @@ options = options || {};

if (cache && !maxAge) maxAge = cache;
maxAge = maxAge || MAX_AGE;
maxAge = maxAge || 0;
}

@@ -66,0 +60,0 @@

@@ -13,2 +13,3 @@

var queryString = require('querystring'),
parseUrl = require('url').parse,
crypto = require('crypto'),

@@ -19,2 +20,20 @@ Path = require('path'),

/**
* Memory cache.
*/
var cache = {};
/**
* Memoized url.parse().pathname.
*
* @param {String} url
* @return {Object}
* @api public
*/
exports.pathname = function(url){
return cache[url] || (cache[url] = parseUrl(url).pathname);
}
/**
* Return md5 hash of the given string and optional encoding,

@@ -21,0 +40,0 @@ * defaulting to hex.

{
"name": "connect",
"description": "High performance middleware framework",
"version": "0.5.2",
"version": "0.5.3",
"contributors": [

@@ -6,0 +6,0 @@ { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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