mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed 404 handling for {admin url}/content/* routes
no issue - added our theme error handling middleware to {admin}/content/ so that cache headers are properly set for 404s - only registered {admin}/content when a separate admin url is configured so that we're not overriding {site}/content
This commit is contained in:
parent
6feeb67d84
commit
717567995b
1 changed files with 19 additions and 8 deletions
|
@ -44,20 +44,31 @@ module.exports = function setupParentApp(options = {}) {
|
||||||
// This sets global res.locals which are needed everywhere
|
// This sets global res.locals which are needed everywhere
|
||||||
parentApp.use(shared.middlewares.ghostLocals);
|
parentApp.use(shared.middlewares.ghostLocals);
|
||||||
|
|
||||||
// Wrap the admin and API apps into a single express app for use with vhost
|
|
||||||
const adminApp = express();
|
|
||||||
adminApp.enable('trust proxy'); // required to respect x-forwarded-proto in admin requests
|
|
||||||
adminApp.use('/ghost/api', require('./api')());
|
|
||||||
adminApp.use('/ghost', require('./admin')());
|
|
||||||
// TODO: remove /content/* once we're sure the API is not returning relative asset URLs anywhere
|
|
||||||
adminApp.use(STATIC_IMAGE_URL_PREFIX, shared.middlewares.image.handleImageSizes, storage.getStorage().serve());
|
|
||||||
|
|
||||||
// Mount the apps on the parentApp
|
// Mount the apps on the parentApp
|
||||||
|
|
||||||
const adminHost = config.get('admin:url') ? (new URL(config.get('admin:url')).hostname) : '';
|
const adminHost = config.get('admin:url') ? (new URL(config.get('admin:url')).hostname) : '';
|
||||||
const frontendHost = new URL(config.get('url')).hostname;
|
const frontendHost = new URL(config.get('url')).hostname;
|
||||||
const hasSeparateAdmin = adminHost && adminHost !== frontendHost;
|
const hasSeparateAdmin = adminHost && adminHost !== frontendHost;
|
||||||
|
|
||||||
|
// Wrap the admin and API apps into a single express app for use with vhost
|
||||||
|
const adminApp = express();
|
||||||
|
adminApp.enable('trust proxy'); // required to respect x-forwarded-proto in admin requests
|
||||||
|
adminApp.use('/ghost/api', require('./api')());
|
||||||
|
adminApp.use('/ghost', require('./admin')());
|
||||||
|
|
||||||
|
// TODO: remove {admin url}/content/* once we're sure the API is not returning relative asset URLs anywhere
|
||||||
|
// only register this route if the admin is separate so we're not overriding the {site}/content/* route
|
||||||
|
if (hasSeparateAdmin) {
|
||||||
|
adminApp.use(
|
||||||
|
STATIC_IMAGE_URL_PREFIX,
|
||||||
|
[
|
||||||
|
shared.middlewares.image.handleImageSizes,
|
||||||
|
storage.getStorage().serve(),
|
||||||
|
shared.middlewares.errorHandler.handleThemeResponse
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ADMIN + API
|
// ADMIN + API
|
||||||
// with a separate admin url only serve on that host, otherwise serve on all hosts
|
// with a separate admin url only serve on that host, otherwise serve on all hosts
|
||||||
const adminVhostArg = hasSeparateAdmin && adminHost ? adminHost : /.*/;
|
const adminVhostArg = hasSeparateAdmin && adminHost ? adminHost : /.*/;
|
||||||
|
|
Loading…
Add table
Reference in a new issue