V
V
VoisHunter2019-05-17 11:46:05
JavaScript
VoisHunter, 2019-05-17 11:46:05

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

2 answer(s)
S
Shohruh Shaimardonov, 2019-05-17
@joeberetta

Here is a link to the manual for redirecting to Apache

M
Marat Maksumov, 2019-05-18
@MaxMind

https://stackoverflow.com/questions/15801014/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question