Permalink
Browse files

non-streaming example

  • Loading branch information...
1 parent 10760d6 commit 1831dbc6268170123ffabff730924a637f34f53c @substack committed Aug 20, 2011
Showing with 43 additions and 0 deletions.
  1. +9 −0 example/get/index.html
  2. +15 −0 example/get/main.js
  3. +19 −0 example/get/server.js
View
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>xhr</title>
+ <script type="text/javascript" src="/browserify.js"></script>
+ </head>
+ <body>
+ <div id="result"></div>
+ </body>
+</html>
View
@@ -0,0 +1,15 @@
+var http = require('http');
+
+http.get({ path : '/beep' }, function (res) {
+ var div = document.getElementById('result');
+
+ div.innerHTML += JSON.stringify(res.headers) + '<br>';
+
+ res.on('data', function (buf) {
+ div.innerHTML += buf;
+ });
+
+ res.on('end', function () {
+ div.innerHTML += '!';
+ });
+});
View
@@ -0,0 +1,19 @@
+var express = require('express');
+var app = express.createServer();
+app.use(express.static(__dirname));
+
+app.get('/beep', function (req, res) {
+ res.setHeader('content-type', 'text/plain');
+ res.end('boop');
+});
+
+var browserify = require('browserify');
+var bundle = browserify({
+ entry : __dirname + '/main.js',
+ require : { http : 'http-browserify' },
+ watch : true
+});
+app.use(bundle);
+
+console.log('Listening on :8082');
+app.listen(8082);

0 comments on commit 1831dbc

Please sign in to comment.