Answer the question
In order to leave comments, you need to log in
How to redirect from http to https Node.JS?
Hello! Help me redirect from http to https Node.JS, according to the manuals, something does not work out, I provide the application config
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var app_1 = require("./app");
var http = require('http');
var https = require('https');
/*Start SSL*/
var fs = require('fs');
var httpProxy = require('http-proxy');
var privateKey = fs.readFileSync('/var/www/httpd-
cert/voishunter/cer.key').toString();
var certificate = fs.readFileSync('/var/www/httpd-
cert/voishunter/cer.crt').toString();
var chainCertificate = fs.readFileSync('/var/www/httpd-
cert/voishunter/cer.ca').toString();
httpProxy.createServer({
target: {
host: 'localhost',
port: 3000
},
ssl: {
key: privateKey,
cert: certificate,
ca: chainCertificate
}
}).listen(4000);
/*End SSL*/
var Server = /** @class */ (function () {
function Server() {
this.port = this.normalizePort(process.env.PORT || '3000');
app_1.app.set('port', this.port);
this.server = http.createServer(app_1.app);
this.server.listen(this.port);
this.server.on('error', this.onError);
}
Server.prototype.normalizePort = function (val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
};
Server.prototype.onError = function (error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof this.port === 'string'
? 'Pipe ' + this.port
: 'Port ' + this.port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
};
return Server;
}());
var kek = new Server();
Answer the question
In order to leave comments, you need to log in
Here is a link to the manual for redirecting to Apache
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question