mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
HTTPS redirect
This commit is contained in:
Submodule qminingPublic/moodle-test-userscript updated: 2c815c8d20...f8d4bf2a41
15
server.js
15
server.js
@@ -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,
|
||||
|
Reference in New Issue
Block a user