a68592a6b9
* 🔥 kill apiUrl helper, use urlFor helper instead More consistency of creating urls. Creates an easier ability to add config changes. Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs. The url util need's refactoring anyway. * 🔥 urlSSL Remove all urlSSL usages. Add TODO's for the next commit to re-add logic for deleted logic. e.g. - cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available - theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag) The changes in this commit doesn't have to be right, but it helped going step by step. The next commit is the more interesting one. * 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic I wanted to remove the forceAdminSSL as separate commit, but was hard to realise. That's why both changes are in one commit: 1. remove forceAdminSSL 2. add admin.url option - fix TODO's from last commits - rewrite the ssl middleware! - create some private helper functions in the url helper to realise the changes - rename some wordings and functions e.g. base === blog (we have so much different wordings) - i would like to do more, but this would end in a non readable PR - this commit contains the most important changes to offer admin.url option * 🤖 adapt tests IMPORTANT - all changes in the routing tests were needed, because each routing test did not start the ghost server - they just required the ghost application, which resulted in a random server port - having a random server port results in a redirect, caused by the ssl/redirect middleware * 😎 rename check-ssl middleware * 🎨 fix theme-handler because of master rebase
71 lines
2.4 KiB
JavaScript
71 lines
2.4 KiB
JavaScript
var debug = require('debug')('ghost:admin'),
|
|
config = require('../config'),
|
|
express = require('express'),
|
|
adminHbs = require('express-hbs').create(),
|
|
|
|
// Admin only middleware
|
|
redirectToSetup = require('../middleware/redirect-to-setup'),
|
|
|
|
// Global/shared middleware?
|
|
cacheControl = require('../middleware/cache-control'),
|
|
urlRedirects = require('../middleware/url-redirects'),
|
|
errorHandler = require('../middleware//error-handler'),
|
|
maintenance = require('../middleware/maintenance'),
|
|
prettyURLs = require('../middleware//pretty-urls'),
|
|
serveStatic = require('express').static,
|
|
utils = require('../utils');
|
|
|
|
module.exports = function setupAdminApp() {
|
|
debug('Admin setup start');
|
|
var adminApp = express();
|
|
|
|
// First determine whether we're serving admin or theme content
|
|
// @TODO finish refactoring this away.
|
|
adminApp.use(function setIsAdmin(req, res, next) {
|
|
res.isAdmin = true;
|
|
next();
|
|
});
|
|
|
|
// @TODO replace all this with serving ember's index.html
|
|
// Create a hbs instance for admin and init view engine
|
|
adminApp.set('view engine', 'hbs');
|
|
adminApp.set('views', config.get('paths').adminViews);
|
|
adminApp.engine('hbs', adminHbs.express3({}));
|
|
// Register our `asset` helper
|
|
adminHbs.registerHelper('asset', require('../helpers/asset'));
|
|
|
|
// Admin assets
|
|
// @TODO ensure this gets a local 404 error handler
|
|
adminApp.use('/assets', serveStatic(
|
|
config.get('paths').clientAssets,
|
|
{maxAge: utils.ONE_YEAR_MS, fallthrough: false}
|
|
));
|
|
|
|
// Render error page in case of maintenance
|
|
adminApp.use(maintenance);
|
|
|
|
// Force SSL if required
|
|
// must happen AFTER asset loading and BEFORE routing
|
|
adminApp.use(urlRedirects);
|
|
|
|
// Add in all trailing slashes & remove uppercase
|
|
// must happen AFTER asset loading and BEFORE routing
|
|
adminApp.use(prettyURLs);
|
|
|
|
// Cache headers go last before serving the request
|
|
// Admin is currently set to not be cached at all
|
|
adminApp.use(cacheControl('private'));
|
|
// Special redirects for the admin (these should have their own cache-control headers)
|
|
adminApp.use(redirectToSetup);
|
|
|
|
// Finally, routing
|
|
adminApp.get('*', require('./controller'));
|
|
|
|
adminApp.use(errorHandler.pageNotFound);
|
|
adminApp.use(errorHandler.handleHTMLResponse);
|
|
|
|
debug('Admin setup end');
|
|
|
|
return adminApp;
|
|
};
|