Webserver with https enabled not working

Hello!

I am facing issues (HTTP ERROR 502) trying to make a simple Express ou Vanilla Https web server working inside Render.

I can’t put the certificates here, but just to enable the HTTPS without pass the certifications paths, makes the web service not work inside Render. (works locally).
Below I have a Vanilla sample, but also tried with Express and Fastify, all the same error.

Why this code below doesn’t work?

‘’’
const https = require(‘https’);
const fs = require(‘fs’);
const path = require(‘path’);
const HttpDispatcher = require(‘httpdispatcher’);

const dispatcher = new HttpDispatcher();
const SERVER_PORT = 3000;

const options = {
cert: fs.readFileSync(path.join(process.cwd(), ‘./api/certs/api_cert.pem’), ‘ascii’).toString(),
key: fs.readFileSync(path.join(process.cwd(), ‘./api/certs/api_key.pem’), ‘ascii’).toString(),
ca: fs.readFileSync(path.join(process.cwd(), ‘./api/certs/chain-pix-prod.crt’), ‘ascii’).toString(),
minVersion: ‘TLSv1.2’,
requestCert: true,
rejectUnauthorized: false,
};

function handleRequest(request, response) {
try {
console.log(request.url);
dispatcher.dispatch(request, response);
} catch (err) {
console.log(err);
}
}
const server = https.createServer(options, handleRequest).listen(SERVER_PORT, () => {
const { port } = server.address();
console.log(Listening on https://127.0.0.1:${port});
});

dispatcher.onGet(’/’, (req, res) => {
res.setHeader(‘Content-Type’, ‘application/json’);
res.end(JSON.stringify({ hello: ‘world’ }));
});

dispatcher.onError((req, res) => {
res.writeHead(404);
res.end(“Error, the URL doesn’t exist”);
});

‘’’

1 Like

Hello,

Render automatically terminates SSL at the load balancer, so your application will always receive an insecure request. If your app is rejecting insecure requests, that would be why you are getting the 502.

1 Like

The Payment platform we are testing, request to use CA certificate to handle authenticated connections etc.
So I will have to create the Webhook outside Render.