Instantly share code, notes, and snippets.

Embed
What would you like to do?
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