Configuring multiple HTTPS servers to listen on a single port in Node.js

By neglecting to specify a protocol, the code snippet below will establish an HTTPS server utilizing TLS 1.2:

var options = {
    key: fs.readFileSync("security/server.key"),
    cert: fs.readFileSync("security/server.crt")
};
https.createServer(options, app).listen(443);

However, I have a specific endpoint that needs to function as a subscriber endpoint for the Fitbit API, which specifically requires TLS 1.0. To achieve this, I must configure secureProtocol to utilize TLSv1_method.

var options = {
    key: fs.readFileSync("security/server.key"),
    cert: fs.readFileSync("security/server.crt"),
    secureProtocol: "TLSv1_method" // Fitbit subscription API requires TLS 1.0
};
https.createServer(options, app).listen(443);

Is there a recommended approach to implement TLS 1.0 for a single endpoint while using TLS 1.2 for all other endpoints? It is possible that leveraging the http-proxy module could provide a solution, although interpreting the documentation to suit my requirements has proven challenging. Please note that I am segregating traffic based on different subdomains.

Answer №1

If the secureProtocol option is not specified, node will automatically create an HTTPS server that supports TLS 1.0, TLS 1.1, and TLS 1.2.


Check out this sample server setup:

const https = require('https');
const fs = require('fs');

const options = {
  key: fs.readFileSync('default-key.pem'),
  cert: fs.readFileSync('default-cert.pem')
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

You can test this using curl from the command line:

Attempt to use SSLv3 (will fail as it's disabled by default):

curl --sslv3 https://localhost:8000 -k

Test for TLSv1 (should work):

curl --tlsv1.0 https://localhost:8000 -k

Test for TLSv1.1 (should work):

curl --tlsv1.1 https://localhost:8000 -k

Test for TLSv1.2 (should work):

curl --tlsv1.2 https://localhost:8000 -k

This has been tested on node.js versions 5.3.0 and 5.5.0 (latest stable).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The email message generated by sendGrid is kept confidential

When attempting to send emails using Node.js with SendGrid, I am experiencing an issue where the email content is always hidden. Here is my node.js code: const msg = { to: 'example@example.com', from: 'sender@example.com', ...

Encountering issues with NPM commands, consistently receiving an error code 127 when attempting to install packages

Recently, I've been working on an Express app on my Windows machine and everything was running smoothly until yesterday. However, today none of my npm commands seem to be working. npm install is producing the following result: https://i.stack.imgur. ...

Comparison: performing joins on the database engine versus on the client side

Currently, I am developing an API using express.js for a food application. However, I am facing some challenges in determining the most efficient method to query the data and transmit it to the client-side. Any suggestions or guidance on this matter would ...

Guide on setting up route aliases in the specific service configurations within Molecular, rather than in the API gateway service

Is it possible to put route aliases in individual service settings instead of the API service as mentioned in the documentation? For example, let's consider a scenario where there is a users service and an API gateway. The users service has a role a ...

Running tasks in the background with Express.js after responding to the client

Operating as a basic controller, this system receives user requests, executes tasks, and promptly delivers responses. The primary objective is to shorten the response time in order to prevent users from experiencing unnecessary delays. Take a look at the ...

Travis is checking to see if the undefined value is being

My experience with jasmine testing has been successful when done locally. However, I am encountering issues on Travis CI where all the API tests are returning undefined values. Here is an example: 4) Checking Server Status for GET /api/v1/orders - Expecte ...

Guide to executing a fetch request recursively within a sequence of multiple fetch requests

I have been developing a node.js and express web application that utilizes the node-fetch module. Here, I am sharing a snippet of the crucial parts of my code: fetchGeoLocation(geoApiKey) .then(coordinates => { data x = getSomeData(); //returns nece ...

sequenced pauses within a sequence of interconnected methods in a class

scenario: There are two javascript classes stored in separate files, each utilizing a different external service and being called within an express.js router. Refer to the "problematic code" section below: route routes.post('/aws', upload.sing ...

Leverage the power of Typescript to flatten a JSON model with the help of Class

Currently, I'm exploring how to utilize the class transformer in TypeScript within a Node.js environment. You can find more information about it here: https://github.com/typestack/class-transformer My goal is to flatten a JSON structure using just on ...

What is the procedure for uploading files via a multiple file input element?

I am attempting to enable the upload of multiple files from multiple input elements within a single form. For example: <form id="category-form" method="post" enctype="multipart/form-data" class="form" name="form"> <div class=" ...

What is the process for spawning a terminal instance within a NodeJS child process?

I'm in the process of setting up a discord channel to serve as an SSH terminal. This involves using a NodeJS server to establish the connection. A custom command will then be used to spawn a new terminal instance that can function as a shell. However ...

The analysis of JSDom varies when running on Heroku compared to running locally

I've encountered a strange issue. I'm trying to gather information from a webpage (such as this one). When I test it locally, everything works fine and I can retrieve all the necessary details. However, when I deploy my script to Heroku, jsdom o ...

Executing SQL queries simultaneously

Currently, I have this code that contains 3 SQL queries running one after the other. However, the query execution time is quite high. So, I've been wondering if there's a way to run all these queries in parallel and then return the results altoge ...

Which is the correct choice: sequelize model, migration file, or foreign key?

When I first delved into studying sequelize, I was completely lost. I found myself simply copying and pasting code when it came to establishing relationships between two models. I struggled to understand whether I needed to insert foreign keys in both the ...

What is the process for generating a file in Node and Express on my server and subsequently transmitting it to my client for download? My technology stack includes NextJS for both frontend and backend operations

How can I generate a file using Express and Node on my server, and then successfully download it to the client? My tech stack includes NextJS for both frontend and backend, and with React as the frontend framework. I'm facing difficulty figuring out h ...

Sinon does not mock the 'import' function

I encountered an issue with the code below. Sinon was unable to successfully mock the doSomething() function, and instead of returning 'hello', it printed the actual string. //file.js import { doSomething } from 'my-npm-package'; modu ...

Passing Node.js MySQL query results to the next function within an async.waterfall workflow

In my node.js code using express, I have set up a route to request data from a mysql database. My goal is to pass the returned JSON in tabular form to another function to restructure it into a hierarchy type JSON. I have individually tested the script to ...

Enhance the visual representation of live updates through the utilization of socket.io in Express

I'm using handlebars as the view engine for my express app. But I'm unsure how to append new data coming in from socket.io. router.get('/', function(req, res) { io.on('connection', function(client) { client.on( ...

Preparing the node_modules directory for deployment and shipping

We are facing a unique challenge with our deployment/shipment process. Our software is being packaged into an archive and sent to Africa where the client's machine lacks reliable Internet access - it may have very limited connectivity or be extremely ...

Node.js application encounters a challenge with Swagger UI requirement not being met

My Node.js application utilizes Electron v15.3.1 and includes a Swagger UI for OAS file viewing, specifically version 4.6.1. Due to a security vulnerability in the Swagger UI, I need to upgrade it. Initially, I attempted to resolve the issue by running np ...