How to deal with http2 ?
See original GitHub issueContext
- hapi-swagger version: 9.1.3
- any other relevant information: node 10.9.0
What are you trying to achieve or the steps to reproduce?
I currently use hapi-swagger and hapi-swagered-ui with http. I want to migrate to http2.
No problem to reach my routes when I use http2 but impossible to run hapi-swagger.
import * as http2 from 'http2';
import * as fs from 'fs';
import * as path from 'path';
import Hapi from 'hapi';
import Inert from 'inert';
import Vision from 'vision';
import HapiSwagger from 'hapi-swagger';
import HapiSwaggerUI from 'hapi-swaggered-ui';
const port = 5000;
const protocol = 'http2';
const getPath = filepath => path.resolve(__dirname, filepath);
const getFile = async (filepath, encoding = 'utf8') => fs.readFileSync(getPath(filepath), encoding);
const getHttp2Listener = async () => http2.createSecureServer({
key: await getFile('./certs/server.key'),
cert: await getFile('./certs/server.crt'),
});
async function StartServer() {
const server = new Hapi.Server(
protocol === 'http2'
? { listener: await getHttp2Listener(), tls: true, port }
: { host: 'localhost', port },
);
await server.register([
Inert,
Vision,
{
plugin: HapiSwagger,
options: {
documentationPage: false,
},
},
{
plugin: HapiSwaggerUI,
options: {
title: 'OpenJam API Documentation',
path: '/docs',
authorization: null,
swaggerEndpoint: '/swagger.json',
},
swaggerOptions: {},
},
]);
server.route([
{
method: 'GET',
path: '/ping',
handler: () => ({ pong: true }),
},
]);
await server.start();
console.log(`Protocol: ${protocol}`);
console.log(`Server running on ${port}...`);
console.log(`Check-out ${server.info.uri} `);
}
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
StartServer().catch(err => console.log(err));
What result did you get?
Failed to load resource: the server responded with a status of 500 ()
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Introduction to HTTP/2 - web.dev
The primary goals for HTTP/2 are to reduce latency by enabling full request and response multiplexing, minimize protocol overhead via efficient compression of ......
Read more >HTTP/2 Frequently Asked Questions
Clients looking to implement HTTP/2 only will need to treat HTTP/1.1 responses without a 101 status code as errors. h2c -only servers can...
Read more >How to Use HTTP/2 to Speed Up Your Websites and Apps
You need to get an SSL certificate and move to HTTPS because Firefox and Chrome only support HTTP/2 over TLS using the new...
Read more >7 Tips for Faster HTTP/2 Performance
Decide if You Need HTTP/2 Today; Terminate HTTP/2 and TLS; Consider Starting with SPDY; Identify HTTP/1.x Optimizations in Your Code; Implement ...
Read more >What is HTTP/2 – The Ultimate Guide
This in-depth guide explains HTTP/2 for end-users and developers. From basic information to more advanced topics.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue above could also be related to
...? { listener: await getHttp2Listener(), tls: true, port }
http2.createSecureServer
isTLS/https
by default so it seems redundant (maybe a collision) to enable HAPItls: true
and have the listener on https as well. In any rate I believe it’s a configuration issue and not anything wrong with hapi-swagger.@morgangraphics thanks for analysis. I’ve tagged the issue for documentation. Probably a good opportunity to add an example or some docs in the README.