Skip to content

Commit c9b96a0

Browse files
committed
https func to middleware folder
1 parent 3524f2c commit c9b96a0

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

server/app.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path')
88
const dns = require('dns')
99
const os = require('os')
1010
const mongoose = require('mongoose')
11+
const httpToHttps = require('./middleware/httpToHttps.middleware')
1112
require('dotenv').config()
1213

1314
/**
@@ -87,14 +88,3 @@ function logServerStart() {
8788
if (err) console.log(err)
8889
})
8990
}
90-
91-
/**
92-
* перенаправление с http на https для PWA
93-
*/
94-
function httpToHttps(req, res, next) {
95-
if (req.header('x-forwarded-proto') !== 'https') {
96-
res.redirect(`https://${req.header('host')}${req.url}`)
97-
} else {
98-
next()
99-
}
100-
}

server/middleware/auth.middleware.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* @file auth.middleware.js
3-
*/
1+
/** @file auth.middleware.js */
42
const jwt = require('jsonwebtoken')
53
require('dotenv').config()
64

@@ -9,7 +7,6 @@ require('dotenv').config()
97
* @param {*} req
108
* @param {*} res
119
* @param {*} next
12-
*
1310
*/
1411
module.exports = (req, res, next) => {
1512
//проверка работы сервера
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @file httpToHttps.middleware.js */
2+
/**
3+
* Перенаправление с http на https для PWA
4+
* @param {*} req
5+
* @param {*} res
6+
* @param {*} next
7+
*/
8+
module.exports = (req, res, next) => {
9+
if (req.header('x-forwarded-proto') !== 'https') {
10+
res.redirect(`https://${req.header('host')}${req.url}`)
11+
} else {
12+
next()
13+
}
14+
}

0 commit comments

Comments
 (0)