Answer the question
In order to leave comments, you need to log in
Nodejs + expressjs + http2?
Actually decided to transfer the site to https. Got a certificate.
const
fs = require('fs'),
express = require('express'),
app = express(),
http = require('http'),
http2 = require('http2'),
https = require('https'),
spdy = require('spdy');
app.use(express.static(__dirname + '/public'));
const
credentials = {
key: fs.readFileSync('./sslcert/privkey.pem', 'utf8'),
cert: fs.readFileSync('./sslcert/cert.pem', 'utf8'),
ca: fs.readFileSync('./sslcert/chain.pem', 'utf8')
};
http
.createServer(app)
.listen(80, (error) => {
if (error) {
console.error(error)
return process.exit(1)
} else {
console.log('Listening on port: 80.')
}
});
https
.createServer(credentials, app)
.listen(443, (error) => {
if (error) {
console.error(error)
return process.exit(1)
} else {
console.log('Listening on port: 443.')
}
});
Answer the question
In order to leave comments, you need to log in
First, do not use http2 with traditional sites built under HTTPS 1.1, you will not actually feel any bonus. The problem is that resource preloading can be slower than parallel on-demand resource loading if you don't design your application for http2 in advance. Secondly, http2 is a binary format, not a text one, it has only some support, and not for all mobile browsers, in particular, full support is provided on a bunch of chrome and apache, but not for all platforms. Thirdly, it is easier to register a certificate and automate its issuance using the NGINX setup and the free Let's Encrypt bot for NGINX. Yes, and moving to https under NGINX comes down to elementary operations, and your site, as it worked in http, so let it work, you don’t need to touch it.
I just registered http2 in nginx and everything is displayed normally, those clients who can use http2 get it, those who do not get 1.1, Google gave additional points for SEO for this.
Where the bot proposed above sets the certificate settings, you just need to add http2
listen 443 ssl http2
Node SPDY was completely abandoned for development. As an option, use node lts v10.xx for a local server. For production, as an option to pass pm2 through a CDN (for example, fastly). Between this bundle, you can also add a balancer (for example, from digitalocean). In general, he himself was looking for how to solve this problem, and Google brought me here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question