Skip to content
Myr

express.core.js

This file

Path

lib/express.core.js

126 lines · 3.1 KiB · JavaScript

Last changed by

Added routing spec filevisionmediabefore adoptionbdf2c8f

History of this file

Take it

Initial commitvisionmediabefore adoption9998490

lines 1–2
1
2(function(){

Added Express.contentsOf()visionmediabefore adoption1633662

lines 3–4why, one step back
3 Express = {
4 version : '0.0.1',

Added routing spec filevisionmediabefore adoptionbdf2c8f

lines 5–6why, one step back
5 response : {
6 body : null,

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 7–28why, one step back
7 status : 200,
8 headers : {},9 statuses : {10 'ok' : 200,11 'created' : 201,12 'accepted' : 202,13 'no content' : 204,14 'reset content' : 205,15 'partial content' : 206,16 'moved permanently' : 301,17 'found' : 302,18 'see other' : 303,19 'not modified' : 304,20 'use proxy' : 305,21 'switch proxy' : 306,22 'temporary redirect' : 307,23 'bad request' : 400,24 'unauthorized' : 401,25 'forbidden' : 403,26 'not found' : 40427 }28 },

Added Express.contentsOf()visionmediabefore adoption1633662

lines 29–38why, one step back
29
30 /**31 * Start express, binding to _port_.32 *33 * @param {int} port34 * @api public35 */36 37 start : function(port) {38 this.server.listen(port || 3000, function(request, response){

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

line 39why, one step back
39 response.sendHeader(Express.response.status, Express.hashToArray(Express.response.headers))

Added routing spec filevisionmediabefore adoptionbdf2c8f

line 40why, one step back
40 response.sendBody(Express.response.body || '')

Added Express.contentsOf()visionmediabefore adoption1633662

lines 41–58why, one step back
41 response.finish()
42 })43 },44 45 server : {46 47 /**48 * Listen to _port_ with _callback_.49 *50 * @param {int} port51 * @param {function} callback52 * @api private53 */54 55 listen : function(port, callback) {56 new node.http.Server(callback).listen(port)57 puts('Express running at http://localhost:' + port)58 }

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

lines 59–75why, one step back
59 },
60 61 /**62 * Return an associative array generated63 * from the key / value pairs in _hash_.64 *65 * @param {hash} hash66 * @return {array}67 * @api public68 */69 70 hashToArray : function(hash) {71 var array = []72 for (var key in hash)73 if (hash.hasOwnProperty(key))74 array.push([key, hash[key]])75 return array

Added Express.header()visionmediabefore adoption3b3be54

lines 76–78why, one step back
76 },
77 78 /**

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 79–91why, one step back
79 * Set response status to _value_. Where value may be
80 * a case-insensitive string such as 'Not Found', 'forbidden',81 * or a numeric HTTP response status code.82 *83 * @param {int, string} value84 * @api public85 */86 87 status : function(value) {88 this.response.status = this.response.statuses[value.toString().toLowerCase()] || value89 },90 91 /**

Added Express.header()visionmediabefore adoption3b3be54

lines 92–101why, one step back
92 * Sets _name_ header to _value_. When _value_
93 * is not present the value of the header _name_94 * will be returned (if available).95 *96 * @param {string} name97 * @param {string} value98 * @api public99 */100 101 header : function(name, value) {

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 102–103why, one step back
102 return value ? this.response.headers[name] = value :
103 this.response.headers[name]

Added Express.contentsOf()visionmediabefore adoption1633662

lines 104–115why, one step back
104 },
105 106 /**107 * Return the contents of a function body.108 *109 * @param {function} body110 * @return {string}111 * @api public112 */113 114 contentsOf : function(body) {115 return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]

Added routing spec filevisionmediabefore adoptionbdf2c8f

lines 116–119why, one step back
116 },
117 118 routeFunctionFor : function(method) {119

Added Express.contentsOf()visionmediabefore adoption1633662

lines 120–122why, one step back
120 }
121 }122

Added routing spec filevisionmediabefore adoptionbdf2c8f

lines 123–125why, one step back
123 get = Express.routeFunctionFor('get')
124 post = Express.routeFunctionFor('post')125

Initial commitvisionmediabefore adoption9998490

line 126
126})()