...**/!(*.map|*.min.js)Size
Gzip
Dependencies
Publish
Install
@@ -1,7 +1,7 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "express", |
| 3 | 3 | "description": "Sinatra inspired web development framework", |
| 4 | "version": "2.5.11", | |
| 4 | "version": "3.0.0", | |
| 5 | 5 | "author": "TJ Holowaychuk <tj@vision-media.ca>", |
| 6 | 6 | "contributors": [ |
| 7 | 7 | { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" }, |
@@ -10,29 +10,46 @@ | ||
| 10 | 10 | { "name": "Guillermo Rauch", "email": "rauchg@gmail.com" } |
| 11 | 11 | ], |
| 12 | 12 | "dependencies": { |
| 13 | "connect": "1.x", | |
| 14 | "mime": "1.2.4", | |
| 15 | "qs": "0.4.x", | |
| 16 | "mkdirp": "0.3.0" | |
| 13 | "connect": "2.6.0", | |
| 14 | "commander": "0.6.1", | |
| 15 | "range-parser": "0.0.4", | |
| 16 | "mkdirp": "0.3.3", | |
| 17 | "cookie": "0.0.4", | |
| 18 | "crc": "0.2.0", | |
| 19 | "fresh": "0.1.0", | |
| 20 | "methods": "0.0.1", | |
| 21 | "send": "0.1.0", | |
| 22 | "debug": "*" | |
| 17 | 23 | }, |
| 18 | 24 | "devDependencies": { |
| 19 | "connect-form": "0.2.1", | |
| 20 | "ejs": "0.4.2", | |
| 21 | "expresso": "0.9.2", | |
| 22 | "hamljs": "0.6.x", | |
| 23 | "jade": "0.16.2", | |
| 24 | "stylus": "0.13.0", | |
| 25 | "should": "0.3.2", | |
| 26 | "express-messages": "0.0.2", | |
| 27 | "node-markdown": ">= 0.0.1", | |
| 28 | "connect-redis": ">= 0.0.1" | |
| 25 | "ejs": "*", | |
| 26 | "mocha": "*", | |
| 27 | "jade": "*", | |
| 28 | "hjs": "*", | |
| 29 | "stylus": "*", | |
| 30 | "should": "*", | |
| 31 | "connect-redis": "*", | |
| 32 | "github-flavored-markdown": "*", | |
| 33 | "supertest": "0.0.1" | |
| 29 | 34 | }, |
| 30 | "keywords": ["framework", "sinatra", "web", "rest", "restful"], | |
| 35 | "keywords": [ | |
| 36 | "express", | |
| 37 | "framework", | |
| 38 | "sinatra", | |
| 39 | "web", | |
| 40 | "rest", | |
| 41 | "restful", | |
| 42 | "router", | |
| 43 | "app", | |
| 44 | "api" | |
| 45 | ], | |
| 31 | 46 | "repository": "git://github.com/visionmedia/express", |
| 32 | 47 | "main": "index", |
| 33 | 48 | "bin": { "express": "./bin/express" }, |
| 34 | 49 | "scripts": { |
| 35 | "test": "make test", | |
| 36 | "prepublish" : "npm prune" | |
| 37 | } | |
| 38 | } | |
| 50 | "prepublish" : "npm prune", | |
| 51 | "test": "make test" | |
| 52 | }, | |
| 53 | "engines": { "node": "*" } | |
| 54 | } | |
| 55 | ||
@@ -1,12 +1,9 @@ | ||
| 1 | 1 | |
| 2 | var express = require('./'); | |
| 3 | var app = express.createServer(); | |
| 2 | var express = require('./') | |
| 3 | var app = express(); | |
| 4 | 4 | |
| 5 | app.use(express.logger('dev')); | |
| 6 | ||
| 7 | 5 | app.get('/', function(req, res){ |
| 8 | console.log(req.protocol); | |
| 9 | res.send('hello'); | |
| 6 | res.send('hello world'); | |
| 10 | 7 | }); |
| 11 | 8 | |
| 12 | app.listen(3000); | |
| 9 | app.listen(4000) | |
@@ -1,77 +1,90 @@ | ||
| 1 | ||
| 2 | /*! | |
| 3 | * Express | |
| 4 | * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> | |
| 5 | * MIT Licensed | |
| 6 | */ | |
| 7 | ||
| 8 | 1 | /** |
| 9 | 2 | * Module dependencies. |
| 10 | 3 | */ |
| 11 | 4 | |
| 12 | 5 | var connect = require('connect') |
| 13 | , HTTPSServer = require('./https') | |
| 14 | , HTTPServer = require('./http') | |
| 6 | , proto = require('./application') | |
| 15 | 7 | , Route = require('./router/route') |
| 8 | , Router = require('./router') | |
| 9 | , req = require('./request') | |
| 10 | , res = require('./response') | |
| 11 | , utils = connect.utils; | |
| 16 | 12 | |
| 17 | 13 | /** |
| 18 | * Re-export connect auto-loaders. | |
| 19 | * | |
| 20 | * This prevents the need to `require('connect')` in order | |
| 21 | * to access core middleware, so for example `express.logger()` instead | |
| 22 | * of `require('connect').logger()`. | |
| 14 | * Expose `createApplication()`. | |
| 23 | 15 | */ |
| 24 | 16 | |
| 25 | var exports = module.exports = connect.middleware; | |
| 17 | exports = module.exports = createApplication; | |
| 26 | 18 | |
| 27 | 19 | /** |
| 28 | 20 | * Framework version. |
| 29 | 21 | */ |
| 30 | 22 | |
| 31 | exports.version = '2.5.11'; | |
| 23 | exports.version = '3.0.0'; | |
| 32 | 24 | |
| 33 | 25 | /** |
| 34 | * Shortcut for `new Server(...)`. | |
| 26 | * Expose mime. | |
| 27 | */ | |
| 28 | ||
| 29 | exports.mime = connect.mime; | |
| 30 | ||
| 31 | /** | |
| 32 | * Create an express application. | |
| 35 | 33 | * |
| 36 | * @param {Function} ... | |
| 37 | * @return {Server} | |
| 34 | * @return {Function} | |
| 38 | 35 | * @api public |
| 39 | 36 | */ |
| 40 | 37 | |
| 41 | exports.createServer = function(options){ | |
| 42 | if ('object' == typeof options) { | |
| 43 | return new HTTPSServer(options, Array.prototype.slice.call(arguments, 1)); | |
| 44 | } else { | |
| 45 | return new HTTPServer(Array.prototype.slice.call(arguments)); | |
| 46 | } | |
| 47 | }; | |
| 38 | function createApplication() { | |
| 39 | var app = connect(); | |
| 40 | utils.merge(app, proto); | |
| 41 | app.request = { __proto__: req }; | |
| 42 | app.response = { __proto__: res }; | |
| 43 | app.init(); | |
| 44 | return app; | |
| 45 | } | |
| 48 | 46 | |
| 49 | 47 | /** |
| 50 | * Expose constructors. | |
| 48 | * Expose connect.middleware as express.* | |
| 49 | * for example `express.logger` etc. | |
| 51 | 50 | */ |
| 52 | 51 | |
| 53 | exports.HTTPServer = HTTPServer; | |
| 54 | exports.HTTPSServer = HTTPSServer; | |
| 55 | exports.Route = Route; | |
| 52 | for (var key in connect.middleware) { | |
| 53 | Object.defineProperty( | |
| 54 | exports | |
| 55 | , key | |
| 56 | , Object.getOwnPropertyDescriptor(connect.middleware, key)); | |
| 57 | } | |
| 56 | 58 | |
| 57 | 59 | /** |
| 58 | * View extensions. | |
| 60 | * Error on createServer(). | |
| 59 | 61 | */ |
| 60 | 62 | |
| 61 | exports.View = | |
| 62 | exports.view = require('./view'); | |
| 63 | exports.createServer = function(){ | |
| 64 | console.warn('Warning: express.createServer() is deprecated, express'); | |
| 65 | console.warn('applications no longer inherit from http.Server,'); | |
| 66 | console.warn('please use:'); | |
| 67 | console.warn(''); | |
| 68 | console.warn(' var express = require("express");'); | |
| 69 | console.warn(' var app = express();'); | |
| 70 | console.warn(''); | |
| 71 | return createApplication(); | |
| 72 | }; | |
| 63 | 73 | |
| 64 | 74 | /** |
| 65 | * Response extensions. | |
| 75 | * Expose the prototypes. | |
| 66 | 76 | */ |
| 67 | 77 | |
| 68 | require('./response'); | |
| 78 | exports.application = proto; | |
| 79 | exports.request = req; | |
| 80 | exports.response = res; | |
| 69 | 81 | |
| 70 | 82 | /** |
| 71 | * Request extensions. | |
| 83 | * Expose constructors. | |
| 72 | 84 | */ |
| 73 | 85 | |
| 74 | require('./request'); | |
| 86 | exports.Route = Route; | |
| 87 | exports.Router = Router; | |
| 75 | 88 | |
| 76 | 89 | // Error handler title |
| 77 | 90 | |
@@ -1,10 +1,10 @@ | ||
| 1 | 1 | |
| 2 | /*! | |
| 3 | * Express - router - Route | |
| 4 | * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> | |
| 5 | * MIT Licensed | |
| 2 | /** | |
| 3 | * Module dependencies. | |
| 6 | 4 | */ |
| 7 | 5 | |
| 6 | var utils = require('../utils'); | |
| 7 | ||
| 8 | 8 | /** |
| 9 | 9 | * Expose `Route`. |
| 10 | 10 | */ |
@@ -32,57 +32,41 @@ | ||
| 32 | 32 | this.path = path; |
| 33 | 33 | this.method = method; |
| 34 | 34 | this.callbacks = callbacks; |
| 35 | this.regexp = normalize(path | |
| 35 | this.regexp = utils.pathRegexp(path | |
| 36 | 36 | , this.keys = [] |
| 37 | 37 | , options.sensitive |
| 38 | 38 | , options.strict); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | * Check if this route matches `path` and return captures made. | |
| 42 | * Check if this route matches `path`, if so | |
| 43 | * populate `.params`. | |
| 43 | 44 | * |
| 44 | 45 | * @param {String} path |
| 45 | * @return {Array} | |
| 46 | * @return {Boolean} | |
| 46 | 47 | * @api private |
| 47 | 48 | */ |
| 48 | 49 | |
| 49 | 50 | Route.prototype.match = function(path){ |
| 50 | return this.regexp.exec(path); | |
| 51 | }; | |
| 51 | var keys = this.keys | |
| 52 | , params = this.params = [] | |
| 53 | , m = this.regexp.exec(path); | |
| 52 | 54 | |
| 53 | /** | |
| 54 | * Normalize the given path string, | |
| 55 | * returning a regular expression. | |
| 56 | * | |
| 57 | * An empty array should be passed, | |
| 58 | * which will contain the placeholder | |
| 59 | * key names. For example "/user/:id" will | |
| 60 | * then contain ["id"]. | |
| 61 | * | |
| 62 | * @param {String|RegExp} path | |
| 63 | * @param {Array} keys | |
| 64 | * @param {Boolean} sensitive | |
| 65 | * @param {Boolean} strict | |
| 66 | * @return {RegExp} | |
| 67 | * @api private | |
| 68 | */ | |
| 55 | if (!m) return false; | |
| 69 | 56 | |
| 70 | function normalize(path, keys, sensitive, strict) { | |
| 71 | if (path instanceof RegExp) return path; | |
| 72 | path = path | |
| 73 | .concat(strict ? '' : '/?') | |
| 74 | .replace(/\/\(/g, '(?:/') | |
| 75 | .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){ | |
| 76 | keys.push({ name: key, optional: !! optional }); | |
| 77 | slash = slash || ''; | |
| 78 | return '' | |
| 79 | + (optional ? '' : slash) | |
| 80 | + '(?:' | |
| 81 | + (optional ? slash : '') | |
| 82 | + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' | |
| 83 | + (optional || ''); | |
| 84 | }) | |
| 85 | .replace(/([\/.])/g, '\\$1') | |
| 86 | .replace(/\*/g, '(.*)'); | |
| 87 | return new RegExp('^' + path + '$', sensitive ? '' : 'i'); | |
| 88 | } | |
| 57 | for (var i = 1, len = m.length; i < len; ++i) { | |
| 58 | var key = keys[i - 1]; | |
| 59 | ||
| 60 | var val = 'string' == typeof m[i] | |
| 61 | ? decodeURIComponent(m[i]) | |
| 62 | : m[i]; | |
| 63 | ||
| 64 | if (key) { | |
| 65 | params[key.name] = val; | |
| 66 | } else { | |
| 67 | params.push(val); | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 71 | return true; | |
| 72 | }; | |
@@ -1,29 +1,33 @@ | ||
| 1 | 1 | |
| 2 | DOCS = $(shell find docs/*.md) | |
| 3 | HTMLDOCS = $(DOCS:.md=.html) | |
| 4 | TESTS = $(shell find test/*.test.js) | |
| 2 | MOCHA_OPTS= | |
| 3 | REPORTER = dot | |
| 5 | 4 | |
| 6 | test: | |
| 7 | @NODE_ENV=test ./node_modules/.bin/expresso $(TESTS) | |
| 5 | check: test | |
| 8 | 6 | |
| 9 | docs: $(HTMLDOCS) | |
| 10 | @ echo "... generating TOC" | |
| 11 | @./support/toc.js docs/guide.html | |
| 7 | test: test-unit test-acceptance | |
| 12 | 8 | |
| 13 | %.html: %.md | |
| 14 | @echo "... $< -> $@" | |
| 15 | @markdown $< \ | |
| 16 | | cat docs/layout/head.html - docs/layout/foot.html \ | |
| 17 | > $@ | |
| 9 | test-unit: | |
| 10 | @NODE_ENV=test ./node_modules/.bin/mocha \ | |
| 11 | --reporter $(REPORTER) \ | |
| 12 | $(MOCHA_OPTS) | |
| 18 | 13 | |
| 19 | site: | |
| 20 | rm -fr /tmp/docs \ | |
| 21 | && cp -fr docs /tmp/docs \ | |
| 22 | && git checkout gh-pages \ | |
| 23 | && cp -fr /tmp/docs/* . \ | |
| 24 | && echo "done" | |
| 14 | test-acceptance: | |
| 15 | @NODE_ENV=test ./node_modules/.bin/mocha \ | |
| 16 | --reporter $(REPORTER) \ | |
| 17 | --bail \ | |
| 18 | test/acceptance/*.js | |
| 25 | 19 | |
| 26 | docclean: | |
| 27 | rm -f docs/*.{1,html} | |
| 20 | test-cov: lib-cov | |
| 21 | @EXPRESS_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html | |
| 28 | 22 | |
| 29 | .PHONY: site test docs docclean | |
| 23 | lib-cov: | |
| 24 | @jscoverage lib lib-cov | |
| 25 | ||
| 26 | benchmark: | |
| 27 | @./support/bench | |
| 28 | ||
| 29 | clean: | |
| 30 | rm -f coverage.html | |
| 31 | rm -fr lib-cov | |
| 32 | ||
| 33 | .PHONY: test test-unit test-acceptance benchmark clean | |
@@ -0,0 +1,25 @@ | ||
| 1 | ||
| 2 | var http = require('http'); | |
| 3 | ||
| 4 | var times = 50; | |
| 5 | ||
| 6 | while (times--) { | |
| 7 | var req = http.request({ | |
| 8 | port: 3000 | |
| 9 | , method: 'POST' | |
| 10 | , headers: { 'Content-Type': 'application/x-www-form-urlencoded' } | |
| 11 | }); | |
| 12 | ||
| 13 | req.on('response', function(res){ | |
| 14 | console.log(res.statusCode); | |
| 15 | }); | |
| 16 | ||
| 17 | var n = 500000; | |
| 18 | while (n--) { | |
| 19 | req.write('foo=bar&bar=baz&'); | |
| 20 | } | |
| 21 | ||
| 22 | req.write('foo=bar&bar=baz'); | |
| 23 | ||
| 24 | req.end(); | |
| 25 | } | |
@@ -0,0 +1,33 @@ | ||
| 1 | ||
| 2 | /** | |
| 3 | * Module dependencies. | |
| 4 | */ | |
| 5 | ||
| 6 | var utils = require('./utils'); | |
| 7 | ||
| 8 | /** | |
| 9 | * Initialization middleware, exposing the | |
| 10 | * request and response to eachother, as well | |
| 11 | * as defaulting the X-Powered-By header field. | |
| 12 | * | |
| 13 | * @param {Function} app | |
| 14 | * @return {Function} | |
| 15 | * @api private | |
| 16 | */ | |
| 17 | ||
| 18 | exports.init = function(app){ | |
| 19 | return function expressInit(req, res, next){ | |
| 20 | req.app = res.app = app; | |
| 21 | if (app.settings['x-powered-by']) res.setHeader('X-Powered-By', 'Express'); | |
| 22 | req.res = res; | |
| 23 | res.req = req; | |
| 24 | req.next = next; | |
| 25 | ||
| 26 | req.__proto__ = app.request; | |
| 27 | res.__proto__ = app.response; | |
| 28 | ||
| 29 | res.locals = res.locals || utils.locals(res); | |
| 30 | ||
| 31 | next(); | |
| 32 | } | |
| 33 | }; | |
Publish
Install