HTTPS redirect

This commit is contained in:
MrFry 2020-04-16 08:34:01 +02:00
parent 3ce75eef9e
commit c1fc2a4e5f
2 changed files with 14 additions and 3 deletions

@ -1 +1 @@
Subproject commit 2c815c8d20b6c25a4214d6118760d993f2287f36
Subproject commit f8d4bf2a414d2973582c08bfa8b8b8f19389b2e9

View file

@ -17,8 +17,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
process.stdout.write('\u001b[2J\u001b[0;0H') // console.clear()
const startHTTPS = true
const isRoot = process.getuid && process.getuid() === 0
@ -90,6 +88,19 @@ function exit (reason) {
}
const app = express()
app.use(function (req, res, next) {
if (req.secure) {
next()
} else {
logger.DebugLog(`HTTPS ${req.method} redirect to: ${'https://' + req.headers.host + req.url}`, 'https', 1)
if (req.method === 'POST') {
res.redirect(307, 'https://' + req.headers.host + req.url)
} else {
res.redirect('https://' + req.headers.host + req.url)
}
}
})
// https://github.com/expressjs/cors#configuration-options
app.use(cors({
credentials: true,