mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
no issue
- right now, we mount all API endpoints (v2, v3 and canary), alongside some
other routes, when Ghost is booting. This is wasteful because we don't
necessarily need any of the endpoints to get Ghost up and running
- even when Admin is used, it uses `canary` so `v2` and `v3` sit in memory
- the better approach here is to lazy load these endpoints, so they only
get mounted when needed
- this commit adds the `lazyUse` function into our Express lib,
which takes a mount path and a module function to execute down the
line. This gets passed to the wonderful `express-lazy-router` lib which
detects when we're calling an unmounted module and will mount it for
us
- from local testing, this speeds up boot time by about 18% and reduces
initial memory usage by about 6% 🚀
25 lines
811 B
JavaScript
25 lines
811 B
JavaScript
const debug = require('@tryghost/debug')('frontend');
|
|
const express = require('../../../shared/express');
|
|
|
|
const shared = require('../shared');
|
|
|
|
/**
|
|
*
|
|
* @param {object} options
|
|
* @returns {import('express').RequestHandler}
|
|
*/
|
|
module.exports = (options) => {
|
|
debug('FrontendApp setup start', options);
|
|
|
|
// FRONTEND
|
|
const frontendApp = express('frontend');
|
|
|
|
// Force SSL if blog url is set to https. The redirects handling must happen before asset and page routing,
|
|
// otherwise we serve assets/pages with http. This can cause mixed content warnings in the admin client.
|
|
frontendApp.use(shared.middlewares.urlRedirects.frontendSSLRedirect);
|
|
|
|
frontendApp.lazyUse('/members', require('../members'));
|
|
frontendApp.use('/', require('../site')(options));
|
|
|
|
return frontendApp;
|
|
};
|