molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.78k stars 186 forks source link

Response issue #256

Open saurabh0227 opened 4 years ago

saurabh0227 commented 4 years ago

I'm trying to create a server using http2 and express, but after creating the serving I'm not getting the response from the server to the client. I used a postman to hit the endpoints.

This is my code:

const http2 = require('http2'); const spdy = require('spdy'); const express = require('express'); const bodyParser = require('body-parser'); const fs = require('fs');

const app = express();

app.use(bodyParser.json());

app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type Authorization'); next(); })

const data = { name: 'Saurabh', phone: 2345432167 }

app.get('/data', (req, res, next) => { console.log(data) res.status(200).json(data); next() })

const options = { key: fs.readFileSync('localhost-privkey.pem'), cert: fs.readFileSync('localhost-cert.pem'), allowHTTP1: true } console.log(options) const server = http2.createSecureServer({ options }, app);

server.listen(5000, (err) => { if (err) { throw new Error(err); }

console.log('Listening on port: ' + 5000 + '.');

})

molnarg commented 4 years ago

Did you try using node’s native http2 implementation instead of this project? That should be preferred.

Saurabh kumar notifications@github.com (időpont: 2020. máj. 11., H, 13:35) ezt írta:

I'm trying to create a server using http2 and express, but after creating the serving I'm not getting the response from the server to the client. I used a postman to hit the endpoints.

This is my code:

const http2 = require('http2'); const spdy = require('spdy'); const express = require('express'); const bodyParser = require('body-parser'); const fs = require('fs');

const app = express();

app.use(bodyParser.json());

app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type Authorization'); next(); })

const data = { name: 'Saurabh', phone: 2345432167 }

app.get('/data', (req, res, next) => { console.log(data) res.status(200).json(data); next() })

const options = { key: fs.readFileSync('localhost-privkey.pem'), cert: fs.readFileSync('localhost-cert.pem'), allowHTTP1: true } console.log(options) const server = http2.createSecureServer({ options }, app);

server.listen(5000, (err) => { if (err) { throw new Error(err); }

console.log('Listening on port: ' + 5000 + '.');

})

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/molnarg/node-http2/issues/256, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG2LVIPP2QS4BSDNNO4KL3RQ7PJZANCNFSM4M52RC6Q .