Skip to content

Instantly share code, notes, and snippets.

@sue71
Last active December 13, 2017 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sue71/ece433c8d7a66d9bbc9faa28bc76e6d2 to your computer and use it in GitHub Desktop.
Save sue71/ece433c8d7a66d9bbc9faa28bc76e6d2 to your computer and use it in GitHub Desktop.
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