Skip to content

Commit

Permalink
added example with closing connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Zelenov committed Nov 10, 2016
1 parent 09f6117 commit 30db7e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions example/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable */

const http = require('http');

const options = {
port: '8080',
method: 'GET',
path: '/index'
};

const req = http.request(options);
req.end();

req
.on('response', res => {
let l = 0;
res
.on('end', () => console.log('end, received', l))
.on('data', chunk => {
l += chunk.length;

if (l > 2000) {
res.destroy();
}
});
})
.on('error', e => console.log('error', e));
6 changes: 6 additions & 0 deletions example/tailor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ const tailor = new Tailor({
amdLoaderUrl: AMD_LOADER,
fetchTemplate: fetchTemplateFs(path.join(__dirname, 'templates'), baseTemplateFn)
});

tailor.on('end', (request, contentLength) => {
console.log('sent', contentLength);
});

const server = http.createServer((req, res) => {
if (req.url === '/favicon.ico') {
res.writeHead(200, {'Content-Type': 'image/x-icon'} );
return res.end('');
}

return tailor.requestHandler(req, res);
});
server.listen(8080);
Expand Down

0 comments on commit 30db7e1

Please sign in to comment.