-
-
Save pizycki/65a65fbeb1018dda6c0a83a15acff6e7 to your computer and use it in GitHub Desktop.
Adding HSTS to Ghost Blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Ghost Startup | |
// Orchestrates the startup of Ghost when run from command line. | |
var ghost = require('./core'), | |
express = require('express'), | |
errors = require('./core/server/errors'), | |
parentApp = express(), | |
hsts = require('hsts'), | |
express_enforces_ssl = require('express-enforces-ssl'); | |
// Make sure dependencies are installed and file system permissions are correct. | |
require('./core/server/utils/startup-check').check(); | |
ghost().then(function (ghostServer) { | |
// Force SSL | |
parentApp.enable('trust proxy'); | |
parentApp.use(express_enforces_ssl()); | |
// Force HSTS | |
parentApp.use(hsts({ | |
maxAge: 10886400, // Must be at least 18 weeks to be approved by Google | |
includeSubDomains: true, // Must be enabled to be approved by Google | |
preload: true, | |
force: true | |
})); | |
// Mount our Ghost instance on our desired subdirectory path if it exists. | |
parentApp.use(ghostServer.config.paths.subdir, ghostServer.rootApp); | |
// Let Ghost handle starting our server instance. | |
ghostServer.start(parentApp); | |
}).catch(function (err) { | |
errors.logErrorAndExit(err, err.context, err.help); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment