Skip to content

Instantly share code, notes, and snippets.

@kiliman
Created April 8, 2021 22:00
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 kiliman/9283613572cd73fc55b9a41d52233520 to your computer and use it in GitHub Desktop.
Save kiliman/9283613572cd73fc55b9a41d52233520 to your computer and use it in GitHub Desktop.

Configure HTTP/2 on express with Remix

Remix uses <link rel="modulepreload"/> on client-side JavaScript.

I thought it would be cool to setup HTTP/2 on express to enable pipelining the script files.

Add spdy package, then update server.js to setup server.

Generate self-signed SSL certificate and copy to ./certs folder.

openssl req -x509 -out server.crt -keyout server.key \
-newkey rsa:2048 -nodes -sha256 -days 3650 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
const spdy = require('spdy')
const fs = require('fs')
const path = require('path')
...
let port = process.env.PORT || 443
spdy
.createServer(
{
key: fs.readFileSync(path.join(__dirname, './certs/server.key')),
cert: fs.readFileSync(path.join(__dirname, './certs/server.crt')),
},
app,
)
.listen(port, error => {
if (error) {
console.error(error)
return process.exit(1)
}
console.log(`HTTP/2 server listening on https://localhost:${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment