Added server.js
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 1dcb7ea · Browse files · 1 file·+128 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+128 added−0 removed
- other:+128 added−0 removed
Provenance
- Commit
889f8d9- Tree
c87c9aa- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
1dcb7ea
1 file changed+128 added−0 removed
added:lib/express/server.js+128 added
1+2+/*!3+ * Express - Server4+ * 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+ router = require('connect/middleware/router');15+16+/**17+ * Initialize a new Server with optional middleware.18+ *19+ * @param {Array} middleware20+ * @api public21+ */22+23+var Server = exports = module.exports = function Server(middleware){24+ var self = this;25+ this.config = {};26+ this.settings = {};27+ connect.Server.call(this, middleware || []);28+ this.use('/', router(function(app){29+ self.routes = app;30+ }));31+};32+33+sys.inherits(Server, connect.Server);34+// 35+// /**36+// * Listen on the given port after running configuration blocks.37+// *38+// * @param {Number} port39+// * @api public40+// */41+// 42+// Server.prototype.listen = function(port){43+// var env = process.env.EXPRESS_ENV || process.connectEnv.name;44+// this.runConfig('any', env);45+// connect.Server.prototype.listen.call(this, port);46+// };47+// 48+// /**49+// * Run config callbacks for the given environment(s);50+// *51+// * @param {String} env ...52+// * @return {Server}53+// * @api public54+// */55+// 56+// Server.prototype.runConfig = function(){57+// for (var i = 0, len = arguments.length; i < len; ++i) {58+// var env = arguments[i];59+// if (env in this.config) {60+// var config = this.config[env];61+// config.forEach(function(fn){62+// fn.call(this);63+// }, this);64+// }65+// }66+// return this;67+// };68+// 69+// /**70+// * Assign setting a value71+// *72+// * @param {String} setting73+// * @param {String} val74+// * @return {Server}75+// * @api public76+// */77+// 78+// Server.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 {Server}88+// * @api public89+// */90+// 91+// Server.prototype.enable = function(setting){92+// return this.set(setting, true);93+// };94+// 95+// /**96+// * Disable setting.97+// *98+// * @param {String} setting99+// * @return {Server}100+// * @api public101+// */102+// 103+// Server.prototype.disable = function(setting){104+// return this.set(setting, false);105+// };106+// 107+// /**108+// * Disable setting.109+// *110+// * @param {String} setting111+// * @return {Server}112+// * @api public113+// */114+// 115+// Server.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+ Server.prototype[method] = function(path, fn){124+ this.routes[method](path, fn);125+ return this;126+ };127+ return arguments.callee;128+})('get')('post')('put')('del');