Home > database >  HTTPS request hangs forever (https express server w/ openssl self signed certificate)
HTTPS request hangs forever (https express server w/ openssl self signed certificate)

Time:01-09

Issue: I'm trying to create an HTTPS server using a self signed certificate on openssl. I am able to run the server but when I make a request to "https://localhost:3001", it hangs forever on "Sending request...".

I've tried making the request in the browser (Brave and Chrome) and in Postman, both with the same issue of loading forever. I'm not sure what I am doing wrong?

Here is my code for the server: server.js code

Here is the postman error: enter image description here

CodePudding user response:

You are not using the variable app anywhere in your code. So your API does not have any endpoints, etc.

To fix it add second parameter to createServer with your express.js app like so:

https.createServer({
    key: privateKey,
    cert: certificate
}, app).listen(port);

Notice the second parameter here is app.

Then your server will have the / endpoint and you should get results.

Note: You don't need to do return res.send("Hello World!");.

Just doing res.send("Hello World!"); is enough.

CodePudding user response:

I am not quite sure about, if it will work for you. In my case I was able to fix such issue by including a return statement in the endpoint. Two changes you may try in this are listed below

// Endpoints
app.get('/',(req,res)=> res.send("Hello, World!"); //automatic return

or

// Endpoints
app.get('/',(req,res)=>{
return res.send("Hello, World!");
}

I would also suggest you to add some console.log statements inside the end points, it is good practice to follow and help you debug the request very easily, at least we can understand where the request is actually hanging stuck.

  • Related