This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node.http.createServer(function (request, response) { | |
| node.fs.cat("path/to/your/file.txt", "raws") | |
| .addCallback(function (contents) { | |
| response.sendHeader(200, {"Content-Type": "text/plain", "Content-Length": contents.length}); | |
| response.sendBody(contents); | |
| response.finish(); | |
| }) | |
| .addErrback(function () { | |
| response.sendHeader(404, {"Content-Type": "text/plain"}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function test_getCookie() { | |
| this.req.header = {Cookie: 'foo=bar; '}; | |
| assertMatch(this.request.cookie.foo, "bar"); | |
| this.req.header = {}; | |
| assertMatch(this.request.cookie.foo, "bar"); | |
| this.req.header = {Cookie: 'foo=bar; baz=qux'}; | |
| assertMatch(this.request.cookie.foo, "bar"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| post('/', function () { | |
| this.parseBody() | |
| .addCallback(function (body) { | |
| }); | |
| }); | |
| var promise = new node.Promise(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('/http.js'); | |
| var sys = require('/sys.js'); | |
| var server = http.createServer(function (request, response) { | |
| request.pause(); | |
| request.addListener('body', function (chunk) { | |
| sys.puts("Got body: " + chunk); | |
| }); | |
| request.addListener('complete', function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var p = Promise.join(p1, p2, p3) | |
| p.addCallback(function (p1Res, p2Res, p3Res) { | |
| // p1Res, p2Res, p3Res are arrays | |
| }); | |
| // or // | |
| p.addCallback( | |
| function (p1Res) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sys = require('sys'); | |
| var template ="<html>" + | |
| "<body>" + | |
| "<h1>{{ title }}</h1>" + | |
| "{{# admin }}" + | |
| "If admin {{ name }}" + | |
| "{{/ admin }}" + | |
| "</body>" + | |
| "</html>"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Posix = require('posix'), | |
| Path = require('path'), | |
| sys = require('sys'); | |
| var Mu = exports; | |
| // capture the base proto | |
| var baseProto = ({}).__proto__; | |
| Mu.cache = {}; | |
| Mu.templatePaths = ['.', '']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Reader interface | |
| event: 'data' | |
| event: 'eof' | |
| method: pause() | |
| method: resume() | |
| ## Writer interface | |
| method: write() | |
| method: close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sanitize(string) { | |
| return string.replace(/[&<>"]/g, escapeReplace); | |
| } | |
| function escapeReplace(char) { | |
| switch (char) { | |
| case '<': return '<'; | |
| case '>': return '>'; | |
| case '&': return '&'; | |
| case '"': return '"'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Tested on Node version 0.1.32 and 0.1.33 | |
| var http = require('http'), | |
| sys = require('sys'); | |
| http.createServer(function (request, response) { | |
| response.writeHead(200, {'content-type': 'text/plain'}); | |
| response.write("Hello"); | |
OlderNewer