Created
October 27, 2016 15:53
-
-
Save simonwoo/68c03fae522030f2fd1ed376c13cdc31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const koa = require('koa'); | |
const Readable = require('stream').Readable; | |
const co = require('co') | |
const app = koa(); | |
const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
app.use(function* () { | |
const view = new Readable(); | |
view._read = () => {}; | |
this.body = view; | |
this.type = 'html'; | |
this.status = 200; | |
view.push(` | |
<html> | |
<head> | |
<title>BigPipe Test</title> | |
<style> | |
#loader { | |
width: 100px; | |
height: 100px; | |
border: 1px solid #ccc; | |
text-align: center; | |
vertical-align: middle; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="loader"> | |
<div id="content">Loading</div> | |
</div> | |
`); | |
co(function* () { | |
yield sleep(2000); | |
view.push(` | |
<script> | |
document.getElementById('content').innerHTML = 'Hello World'; | |
</script> | |
`); | |
view.push('</body></html>'); | |
view.push(null); | |
}).catch(e => {}); | |
}); | |
app.listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment