Answer the question
In order to leave comments, you need to log in
How to enable SSL in NodeJS v4.2.1 without using Express.js?
Goodnight.
Installed NodeJS v4.2.1 on Debian Jessie, connected the Socket.IO framework to deliver data via web socket to the browser.
I ran into a problem, I could not connect certificates to connect to NodeJS via HTTPS.
All the examples and documentation say that in order to connect a certificate to NodeJS, you need to use another Express.js framework, is this really true? Or have I misunderstood something?
Here is my working configuration:
var fs = require('fs');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('/home/quotes/ssl/domain.key'),
cert: fs.readFileSync('/home/quotes/ssl/domain.crt'),
ca: fs.readFileSync('/home/quotes/ssl/gd_bundle-g2-g1.crt'),
requestCert: true,
rejectUnauthorized: false,
}
var server = require('https').createServer(options, app);
var io = require('socket.io').listen(server);
Answer the question
In order to leave comments, you need to log in
Have you looked into the docks of the nodes?
First instance: https://nodejs.org/api/https.html#https_https_crea...
What's with the dislike of official documentation?https://nodejs.org/api/https.html#https_https_crea... , everything works fine without express.
Timur Shemsedinov and Konstantin Kitmanov , thank you very much. I'm starting to smoke documentation.
Am I thinking right?
First, I create httpsOptions settings, then I load https, then I create a server with https and with the necessary settings, and then I load socket.io and say that we need to use the already created server.
Am I thinking right?
var fs = require('fs');
var httpsOptions = {
key: fs.readFileSync('/home/quotes/ssl/domain.key'),
cert: fs.readFileSync('/home/quotes/ssl/domain.crt'),
ca: fs.readFileSync('/home/quotes/ssl/gd_bundle-g2-g1.crt'),
requestCert: true,
rejectUnauthorized: false,
}
var https = require('https');
var server = https.createServer(httpsOptions, https).listen(8443);
var io = require('socket.io');
var app = io.listen(server);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question