I have my Angularjs website and I am trying to route all my Http traffic to
Https and for that, I have written below code but it is not working, every
time I am opening my website on Http redirect is not happening.
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public')); // Website part added
var bodyParser = require('body-parser')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
app.use(function(req,res,next) {
if(req.headers["x-forwarded-proto"] == "http") {
res.redirect("https://" + req.headers.host + req.url);
return next();
} else {
console.log('Request was not HTTP');
return next();
}
});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.get('*', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
Can anyone please tell me why this is not working ??
*Edit* - I noticed that whenever I am opening my website then most of the
times this middleware is not getting called. How can this be possible ??
*Edit* - I have my set base href="/" in my index.html will it cause any
problem.
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-appengine/c0ac8bbc-d484-40b6-9339-c4c94b615842%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.