Last active
December 13, 2017 04:58
-
-
Save sue71/ece433c8d7a66d9bbc9faa28bc76e6d2 to your computer and use it in GitHub Desktop.
This file contains 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
const spdy = require('spdy'); | |
const express = require('express'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const app = express(); | |
const publicPath = path.join(__dirname, "."); | |
app.use(express.static(publicPath)); | |
app.get('/push', (req, res) => { | |
if (res.push) { | |
let stream = res.push('/main.js', { | |
req: {'accept': '**/*'}, | |
res: {'content-type': 'application/javascript'} | |
}); | |
stream.on('error', err => { | |
console.log(err); | |
}); | |
stream.end('console.log("Success!")'); | |
} | |
res.end("<script src='/main.js' />"); | |
}); | |
spdy.createServer({ | |
key: fs.readFileSync('./server.key'), | |
cert: fs.readFileSync('./server.crt'), | |
passphrase: 'password' | |
}, app) | |
.listen(8000, (err) => { | |
if (err) { | |
throw new Error(err); | |
} | |
console.log('Listening on port: 8000.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment