Thursday 20 April 2017

Nodejs Change server HTTP to HTTPS

I try change my server to HTTPS, but does not work fine. My page show like I create a new server with anything. In this case I have 2 files, app.js with express required and routes, and my server.js to execute the server require the ./app

My app.js (server-side):

var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests
var http = require('http');
var https = require('https');
//all endpoints is inside my app.js
var app = express();

// endpoints here
//code .. code with routes, code...

module.exports = app;

My server.js (server-side):

    var fs = require('fs')
    var server = require('./app');
    var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;


    var options = {
      key: fs.readFileSync('certificates/xxx.key'),
      cert: fs.readFileSync('certificates/xxx.cer')
    };

    server.listen(port, options, function() {
      console.log('Server execute here %d', port);
    });

Maybe is a newbie question, I can create one server with one file only, but I dont know how to create with this case...

Someone can help me please and explain what I did wrong with this case use?



via Sayuri Mizuguchi

No comments:

Post a Comment