Skip to content

Instantly share code, notes, and snippets.

@futoase
Created October 20, 2012 07:38
Show Gist options
  • Save futoase/3922524 to your computer and use it in GitHub Desktop.
Save futoase/3922524 to your computer and use it in GitHub Desktop.
httpserver sample script
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