feat: Add helmet and force SSL
This commit is contained in:
committed by
Benedikt Rötsch
parent
9ae9c543ba
commit
9c2840ac89
11
app.js
11
app.js
@@ -5,6 +5,7 @@ const cookieParser = require('cookie-parser')
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const logger = require('morgan')
|
const logger = require('morgan')
|
||||||
const querystring = require('querystring')
|
const querystring = require('querystring')
|
||||||
|
const helmet = require('helmet')
|
||||||
|
|
||||||
// Load environment variables using dotenv
|
// Load environment variables using dotenv
|
||||||
require('dotenv').config({ path: 'variables.env' })
|
require('dotenv').config({ path: 'variables.env' })
|
||||||
@@ -24,12 +25,22 @@ app.set('views', path.join(__dirname, 'views'))
|
|||||||
app.set('view engine', 'pug')
|
app.set('view engine', 'pug')
|
||||||
|
|
||||||
app.use(logger('dev'))
|
app.use(logger('dev'))
|
||||||
|
app.use(helmet())
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
app.use(bodyParser.urlencoded({ extended: false }))
|
app.use(bodyParser.urlencoded({ extended: false }))
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
app.use(express.static(path.join(__dirname, 'public')))
|
app.use(express.static(path.join(__dirname, 'public')))
|
||||||
app.use(breadcrumb())
|
app.use(breadcrumb())
|
||||||
|
|
||||||
|
// Force all requests on production to be served over https
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
if (!req.secure && process.env.NODE_ENV === 'production') {
|
||||||
|
var secureUrl = 'https://' + req.headers['host'] + req.url
|
||||||
|
res.writeHead(301, { 'Location': secureUrl })
|
||||||
|
res.end()
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
})
|
||||||
// Set our application state based on environment variables or query parameters
|
// Set our application state based on environment variables or query parameters
|
||||||
app.use(async function (request, response, next) {
|
app.use(async function (request, response, next) {
|
||||||
// Set default settings based on environment variables
|
// Set default settings based on environment variables
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start:watch": "nodemon ./bin/www --ignore public/",
|
"start:watch": "nodemon ./bin/www --ignore public/",
|
||||||
"start": "node ./bin/www",
|
"start:dev": "node ./bin/www",
|
||||||
|
"start:production": "NODE_ENV=production node ./bin/www",
|
||||||
"lint": "eslint ./app.js routes",
|
"lint": "eslint ./app.js routes",
|
||||||
"format": "eslint --fix . bin --ignore public node_modules",
|
"format": "eslint --fix . bin --ignore public node_modules",
|
||||||
"test": "echo 'test'",
|
"test": "echo 'test'",
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
"cookie-parser": "~1.4.3",
|
"cookie-parser": "~1.4.3",
|
||||||
"dotenv": "^4.0.0",
|
"dotenv": "^4.0.0",
|
||||||
"express": "~4.14.0",
|
"express": "~4.14.0",
|
||||||
|
"helmet": "^3.9.0",
|
||||||
"marked": "^0.3.6",
|
"marked": "^0.3.6",
|
||||||
"morgan": "~1.7.0",
|
"morgan": "~1.7.0",
|
||||||
"pug": "~2.0.0-beta6"
|
"pug": "~2.0.0-beta6"
|
||||||
|
|||||||
Reference in New Issue
Block a user