0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Updated admin asset serving for ember-auto-import@2 compatibility (#15128)

refs https://github.com/TryGhost/Admin/pull/2252
closes https://github.com/TryGhost/Team/issues/1182

- Admin now copies it's build output to a single env-specific directory rather than splitting html and assets
  - `core/built/admin/{development|production}/*`
- updated the admin app's `serveStatic` definition for assets and controller's html serving to reflect the new asset paths
This commit is contained in:
Kevin Ansfield 2022-08-02 13:43:45 +01:00 committed by GitHub
parent bcafb84c44
commit 0a34be4012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 18 deletions

View file

@ -126,7 +126,6 @@ test/coverage
# Built asset files
/core/built
/core/frontend/public/ghost.min.css
/core/server/web/admin/views/*.html
# Caddyfile - for local development with ssl + caddy
Caddyfile

View file

@ -1,4 +1,5 @@
const debug = require('@tryghost/debug')('web:admin:app');
const path = require('path');
const express = require('../../../shared/express');
const serveStatic = express.static;
const config = require('../../../shared/config');
@ -16,8 +17,9 @@ module.exports = function setupAdminApp() {
// Admin assets
// @TODO ensure this gets a local 404 error handler
const configMaxAge = config.get('caching:admin:maxAge');
const envDir = config.get('env') === 'production' ? 'production' : 'development';
adminApp.use('/assets', serveStatic(
config.get('paths').adminAssets,
path.join(config.get('paths').adminAssets, envDir, 'assets'),
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS, fallthrough: false}
));

View file

@ -29,8 +29,8 @@ module.exports = function adminController(req, res) {
// CASE: trigger update check unit and let it run in background, don't block the admin rendering
updateCheck();
const defaultTemplate = config.get('env') === 'production' ? 'default-prod.html' : 'default.html';
const templatePath = path.resolve(config.get('paths').adminViews, defaultTemplate);
const envDir = config.get('env') === 'production' ? 'production' : 'development';
const templatePath = path.resolve(config.get('paths').adminAssets, envDir, 'index.html');
const headers = {};
try {

View file

@ -2,10 +2,9 @@
"paths": {
"appRoot": ".",
"corePath": "core/",
"adminAssets": "core/built/assets",
"adminAssets": "core/built/admin",
"adminAuthAssets": "content/public/admin-auth",
"helperTemplates": "core/frontend/helpers/tpl/",
"adminViews": "core/server/web/admin/views/",
"defaultViews": "core/server/views/",
"defaultRouteSettings": "core/server/services/route-settings/",
"internalAppPath": "core/frontend/apps/",

View file

@ -86,7 +86,7 @@ describe('Admin Routing', function () {
describe('built template', function () {
beforeEach(function () {
const configPaths = configUtils.config.get('paths');
configPaths.adminViews = path.resolve('test/utils/fixtures/admin-views');
configPaths.adminAssets = path.resolve('test/utils/fixtures/admin-build');
configUtils.set('paths', configPaths);
});
@ -94,10 +94,10 @@ describe('Admin Routing', function () {
configUtils.restore();
});
it('serves prod file in production', async function () {
it('serves prod assets in production', async function () {
configUtils.set('env', 'production');
const prodTemplate = fs.readFileSync(path.resolve('test/utils/fixtures/admin-views/default-prod.html')).toString();
const prodTemplate = fs.readFileSync(path.resolve('test/utils/fixtures/admin-build/production/index.html')).toString();
const res = await request.get('/ghost/')
.set('X-Forwarded-Proto', 'https')
@ -106,8 +106,8 @@ describe('Admin Routing', function () {
res.text.should.equal(prodTemplate);
});
it('serves dev file when not in production', async function () {
const devTemplate = fs.readFileSync(path.resolve('test/utils/fixtures/admin-views/default.html')).toString();
it('serves dev assets when not in production', async function () {
const devTemplate = fs.readFileSync(path.resolve('test/utils/fixtures/admin-build/development/index.html')).toString();
const res = await request.get('/ghost/')
.set('X-Forwarded-Proto', 'https')

View file

@ -15,7 +15,7 @@ describe('Admin App', function () {
};
configUtils.restore();
configUtils.set('paths:adminViews', path.resolve('test/utils/fixtures/admin-views'));
configUtils.set('paths:adminAssets', path.resolve('test/utils/fixtures/admin-build'));
});
afterEach(function () {

View file

@ -104,7 +104,6 @@ describe('Config Loader', function () {
'adminAssets',
'adminAuthAssets',
'helperTemplates',
'adminViews',
'defaultViews',
'defaultRouteSettings',
'internalAppPath',

View file

@ -2,11 +2,11 @@ const fs = require('fs-extra');
const path = require('path');
const adminFiles = [
'server/web/admin/views/default.html',
'built/assets/ghost.js',
'built/assets/ghost.css',
'built/assets/vendor.js',
'built/assets/vendor.css'
'built/admin/development/index.html',
'built/admin/development/assets/ghost.js',
'built/admin/development/assets/ghost.css',
'built/admin/development/assets/vendor.js',
'built/admin/development/assets/vendor.css'
];
module.exports.stubAdminFiles = () => {