R
R
Roman2019-01-10 12:45:40
Node.js
Roman, 2019-01-10 12:45:40

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.')
        }
    });


The only "working" option, BUT still showing HTTP/1.1.
Tried with spdy - error "RangeError: Invalid typed array length: -4095".
Through http2 the site refuses to open at all.

Who has experienced relocation? According to what manual did you do it and how did it turn out?

https://dassur.ma/things/h2setup/ https://webapplog.com/http2-node/ tried in particular according to these recommendations\manuals

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arthur Mustafin, 2019-01-10
@virtual_hack2root

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.

R
Rostislav, 2020-01-03
@rostikowb

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

I
Ivan Maslov, 2020-02-07
@student_ivan

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 question

Ask a Question

731 491 924 answers to any question