This is my nodejs express setting:
var express = require('express');
var app = express();
app.use(express.static('public'));
app.get('*', function (req, res) {
res.sendfile('public/index.html')
});
app.listen(process.env.PORT || 3000, function () {
console.log('Example app listening on port 3000!');
});
module.exports = app;
I found out that when it use:
app.use(express.static('public'));
Nothing runs inside this get
:
app.get('*', function (req, res) { // nothing runs here res.sendfile('public/index.html') });
ps: I want to redirect (http -> https) inside that get
.
public
directory?express.static()
will only handle things if it finds a matching file. I don't know what your http -> https part of your question is about because you show no code to do that anywhere. - jfriend00express.static()
matches the route, then it will handle it and no request handlers that come after it will see the request. If you want something to run before theexpress.static()
line, then perhaps you want anapp.use()
middleware handler BEFORE theexpress.static()
line. You don't show any code that has anything to do with https so I still have no idea what that is about. - jfriend00