Created
October 20, 2012 07:38
-
-
Save futoase/3922524 to your computer and use it in GitHub Desktop.
httpserver sample script
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
declare function require(name: string); | |
interface Http { | |
createServer(callback: (req: Request, res: Response) => any): CreateServer; | |
} | |
interface CreateServer { | |
listen(port?: number, host?: string); | |
} | |
interface Request { | |
url: string; | |
} | |
interface Response { | |
writeHead(port: number, header: any); | |
end(message: string); | |
} | |
declare var http: Http; | |
http = require('http'); | |
http.createServer(function (req: Request, res: Response){ | |
console.log('path: ' + req.url); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello world'); | |
}).listen(3000, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment