Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response issue #256

Open
saurabh0227 opened this issue May 11, 2020 · 1 comment
Open

Response issue #256

saurabh0227 opened this issue May 11, 2020 · 1 comment

Comments

@saurabh0227
Copy link

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
Copy link
Owner

molnarg commented May 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants