title: How to configure express js 4 to serve some pages in http and others in https?
body: <p>Is there any way to configure a node js application with express js 4 to serve some pages under http protocol and other, those which need more security, in https? </p>
  
  <p>I describe my problem: I'm developing a shop online and I want to display certain pages, like the products list or the product detail views under <code>http</code>, and others which I think need more security, like login or the shopping cart views, under <code>https</code> protocol.</p>
  
  <p>I have tried the <code>express-force-ssl</code> module, but it isn't working. The following code snippet is not from my app (which is too dirty) it is just an example which alos doesn't work for me: </p>
  
  <pre><code>var express = require('express');
  var forceSSL = require('express-force-ssl');
  var fs = require('fs');
  var http = require('http');
  var https = require('https');
  
  var ssl_options = {
    key: fs.readFileSync('./server-private-key.pem'),
    cert: fs.readFileSync('./server-certificate.pem'),
    ca: fs.readFileSync('./server-certificate-signing-request.pem')
  };
  
  var app = express();
  
  var server = http.createServer(app);
  var secureServer = https.createServer(ssl_options, app);
  
  app.use(forceSSL);
  
  app.get('/', function (req, res, next) {
      res.send('&lt;a href="/user/userA"&gt;Hello&lt;/a&gt;')
  });
  app.get('/user/:name', function (req, res, next) {
      var user = req.params.name;
      res.send('&lt;a href="/login"&gt;Hello ' + user + '&lt;/a&gt;')
  });
  app.get('/login', forceSSL, function (req, res, next) {
      res.send('&lt;a href="/"&gt;Hello&lt;/a&gt;&lt;br/&gt;&lt;a href="/logout"&gt;Goodbye&lt;/a&gt;')
  });
  app.get('/logout', forceSSL, function (req, res, next) {
      res.send('&lt;a href="/"&gt;Hello&lt;/a&gt;')
  });
  
  secureServer.listen(443)
  server.listen(8085)
  console.log('server started');
  </code></pre>
  
  <p>The result is that when I launch the application, with url <code>http://localhost:8085</code>, the server automatically redirects it to <code>https://localhost</code> and serves all pages in <code>https</code> protocol. </p>
  
  <p>What I want is to start on <code>http://localhost:8085</code>, navigate to <code>http://localhost/user/userA</code>, then from it go to <code>https://localhost/login</code> and, if click on "Hello" link, I would like to be redirected to <code>http://localhost:8085</code>.</p>
  
  <p>Is there any missing code to get the behavior I want or even any other way to reach it without <code>express-force-ssl</code> module?</p>