Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

works with http-browserify 0.1.1

  • Loading branch information...
commit bceb30e40473a96e766b02c7b02d424a31536d87 0 parents
@substack authored
Showing with 68 additions and 0 deletions.
  1. +19 −0 entry.js
  2. +9 −0 index.html
  3. +12 −0 package.json
  4. +28 −0 server.js
19 entry.js
@@ -0,0 +1,19 @@
+var request = require('request');
+
+$(function () {
+ var res = request('http://localhost:8001/count');
+
+ res.on('data', function (buf) {
+ $('<div>')
+ .text(buf)
+ .appendTo($('#count'))
+ ;
+ });
+
+ res.on('end', function () {
+ $('<div>')
+ .text('__END__')
+ .appendTo($('#count'))
+ ;
+ });
+});
9 index.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="/bundle.js"></script>
+ </head>
+ <body>
+ <div id="count"></div>
+ </body>
+</html>
12 package.json
@@ -0,0 +1,12 @@
+{
+ "name" : "request-browserify-example",
+ "version" : "0.0.0",
+ "repository" : {
+ "type" : "git",
+ "url" : "git://github.com/substack/request-browserify-example.git"
+ },
+ "dependencies" : {
+ "request" : "~2.9.152",
+ "browserify" : "~1.10.2"
+ }
+}
28 server.js
@@ -0,0 +1,28 @@
+#!/usr/bin/env node
+var http = require('http');
+var ecstatic = require('ecstatic')(__dirname);
+
+var server = http.createServer(function (req, res) {
+ if (req.url === '/count') {
+ res.setHeader('content-type', 'multipart/octet-stream');
+
+ var n = 10;
+ var iv = setInterval(function () {
+ res.write(n + '\r\n');
+
+ if (--n === 0) {
+ clearInterval(iv);
+ res.end();
+ }
+ }, 250);
+ }
+ else ecstatic(req, res)
+});
+
+server.listen(8001);
+console.log([
+ 'Listening on :8001',
+ '',
+ 'To compile the build, do:',
+ ' browserify entry.js -o bundle.js'
+].join('\n'));
Please sign in to comment.
Something went wrong with that request. Please try again.