Skip to content

Commit

Permalink
non-streaming example
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 20, 2011
1 parent 10760d6 commit 1831dbc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions example/get/index.html
Original file line number Diff line number Diff line change
@@ -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>
15 changes: 15 additions & 0 deletions example/get/main.js
Original file line number Diff line number Diff line change
@@ -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 += '!';
});
});
19 changes: 19 additions & 0 deletions example/get/server.js
Original file line number Diff line number Diff line change
@@ -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.