Skip to content
Myr

express.core.js

This file

Path

lib/express.core.js

102 lines · 2.5 KiB · JavaScript

Last changed by

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

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 Express.status() and specsvisionmediabefore adoptionaa01cc2

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

Added Express.contentsOf()visionmediabefore adoption1633662

lines 28–57why, one step back
28
29 /**30 * Start express, binding to _port_.31 *32 * @param {int} port33 * @api public34 */35 36 start : function(port) {37 this.server.listen(port || 3000, function(request, response){38 response.sendHeader(200, [['Content-Type', 'text/plain']])39 response.sendBody('Testing')40 response.finish()41 })42 },43 44 server : {45 46 /**47 * Listen to _port_ with _callback_.48 *49 * @param {int} port50 * @param {function} callback51 * @api private52 */53 54 listen : function(port, callback) {55 new node.http.Server(callback).listen(port)56 puts('Express running at http://localhost:' + port)57 }

Added Express.header()visionmediabefore adoption3b3be54

lines 58–60why, one step back
58 },
59 60 /**

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 61–73why, one step back
61 * Set response status to _value_. Where value may be
62 * a case-insensitive string such as 'Not Found', 'forbidden',63 * or a numeric HTTP response status code.64 *65 * @param {int, string} value66 * @api public67 */68 69 status : function(value) {70 this.response.status = this.response.statuses[value.toString().toLowerCase()] || value71 },72 73 /**

Added Express.header()visionmediabefore adoption3b3be54

lines 74–83why, one step back
74 * Sets _name_ header to _value_. When _value_
75 * is not present the value of the header _name_76 * will be returned (if available).77 *78 * @param {string} name79 * @param {string} value80 * @api public81 */82 83 header : function(name, value) {

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

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

Added Express.contentsOf()visionmediabefore adoption1633662

lines 86–101why, one step back
86 },
87 88 /**89 * Return the contents of a function body.90 *91 * @param {function} body92 * @return {string}93 * @api public94 */95 96 contentsOf : function(body) {97 return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]98 }99 }100 101 Express.start()

Initial commitvisionmediabefore adoption9998490

line 102
102})()