.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 5f9e4ac · Browse files · 3 files·+18 added−136 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+18 added−136 removed
- tests:+8 added−4 removed
- other:+10 added−132 removed
Provenance
- Commit
1dcb7ea- Tree
d8b557d- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
5f9e4ac
3 files changed+18 added−136 removed
deleted:lib/express/application.js-132 removed
1-2-/*!3- * Express - Application4- * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>5- * MIT Licensed6- */7-8-/**9- * Module dependencies.10- */11-12-var sys = require('sys'),13- connect = require('connect'),14- rest = require('connect/providers/rest');15-16-/**17- * Initialize a new Application with optional middleware.18- *19- * @param {Array} middleware20- * @api public21- */22-23-var Application = exports.Application = function Application(middleware){24- this.config = {};25- this.settings = {};26- this.routes = { get: [], post: [], put: [], del: []};27- connect.Server.call(this, (middleware || []).concat([28- { provider: 'rest', routes: this.routes }29- ]));30-}31-32-sys.inherits(Application, connect.Server);33-34-/**35- * Listen on the given port after running configuration blocks.36- *37- * @param {Number} port38- * @api public39- */40-41-Application.prototype.listen = function(port){42- var env = process.env.EXPRESS_ENV || process.connectEnv.name;43- this.runConfig('any', env);44- connect.Server.prototype.listen.call(this, port);45-};46-47-/**48- * Run config callbacks for the given environment(s);49- *50- * @param {String} env ...51- * @return {Application}52- * @api public53- */54-55-Application.prototype.runConfig = function(){56- for (var i = 0, len = arguments.length; i < len; ++i) {57- var env = arguments[i];58- if (env in this.config) {59- var config = this.config[env];60- config.forEach(function(fn){61- fn.call(this);62- }, this);63- }64- }65- return this;66-};67-68-69-/**70- * Assign setting a value71- *72- * @param {String} setting73- * @param {String} val74- * @return {Application}75- * @api public76- */77-78-Application.prototype.set = function(setting, val){79- this.settings[setting] = val;80- return this;81-};82-83-/**84- * Enable setting.85- *86- * @param {String} setting87- * @return {Application}88- * @api public89- */90-91-Application.prototype.enable = function(setting){92- return this.set(setting, true);93-};94-95-/**96- * Disable setting.97- *98- * @param {String} setting99- * @return {Application}100- * @api public101- */102-103-Application.prototype.disable = function(setting){104- return this.set(setting, false);105-};106-107-/**108- * Disable setting.109- *110- * @param {String} setting111- * @return {Application}112- * @api public113- */114-115-Application.prototype.configure = function(env, fn){116- if (typeof env === 'function') fn = env, env = 'any';117- (this.config[env] = this.config[env] || []).push(fn);118-};119-120-// Generate RESTful methods121-122-(function(method){123- Application.prototype[method] = function(path, fn){124- var routes = {};125- routes[method] = {};126- routes[method][path] = fn;127- rest.normalize(routes);128- this.routes[method] = this.routes[method].concat(routes[method]);129- return this;130- };131- return arguments.callee;132-})('get')('post')('put')('del');modified:lib/express/index.js+10 added
8 unmodified lines9101112131415161718192021228 unmodified lines * Framework version. */
exports.version = '0.14.0';
/** * Module dependencies. */
var Server = require('./server');
exports.createServer = function(middleware){ return new Server(middleware);};No newline at end of filemodified:test/express.test.js+8 added-4 removed
5 unmodified lines6789101112131011121314151617181920214 unmodified lines5 unmodified lines 'test .version': function(assert){ assert.ok(/^\d+\.\d+\.\d+$/.test(express.version), 'Test express.version format'); }, 'test basic app': function(){ var app = express.createApplication(); var server = connect.createServer(app); app.get('/', function(req, res){ 'test inheritance': function(assert){ var server = express.createServer(); assert.ok(server instanceof connect.Server, 'Test serverlication inheritance'); }, 'test basic server': function(assert){ var server = express.createServer(); server.get('/', function(req, res){ res.writeHead(200, {}); res.end('wahoo'); }); assert.response(server,4 unmodified lines