Serve Hydrogen assets from `/hydrogen-assets/` sub-directory for easier targeting of cache rules (#172)

Fix https://github.com/matrix-org/matrix-public-archive/issues/160
This commit is contained in:
Eric Eastwood 2023-04-19 14:44:12 -05:00 committed by GitHub
parent 17a39ab8db
commit 27afaea8ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 7 deletions

View File

@ -14,7 +14,7 @@ assert(basePath);
// `/r/#room-alias:server/date/2022/10/27` -> `/r/room-alias:server/date/2022/10/27`
function clientSideRoomAliasHashRedirectRoute(req, res) {
const cspNonce = res.locals.cspNonce;
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-styles.css');
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-assets/hydrogen-styles.css');
const stylesUrl = urlJoin(basePath, '/css/styles.css');
const jsBundleUrl = urlJoin(basePath, '/js/entry-client-room-alias-hash-redirect.es.js');

View File

@ -39,12 +39,15 @@ function installRoutes(app) {
// We have to disable no-missing-require lint because it doesn't take into
// account `package.json`. `exports`, see
// https://github.com/mysticatea/eslint-plugin-node/issues/255
// eslint-disable-next-line node/no-missing-require
app.use(express.static(path.dirname(require.resolve('hydrogen-view-sdk/assets/main.js'))));
app.use(
'/hydrogen-assets',
// eslint-disable-next-line node/no-missing-require
express.static(path.dirname(require.resolve('hydrogen-view-sdk/assets/main.js')))
);
app.get(
// This has to be at the root so that the font URL references resolve correctly
'/hydrogen-styles.css',
'/hydrogen-assets/hydrogen-styles.css',
asyncHandler(async function (req, res) {
res.set('Content-Type', 'text/css');
// We have to disable no-missing-require lint because it doesn't take into

View File

@ -61,7 +61,7 @@ router.get(
// We index the room directory unless the config says we shouldn't index anything
const shouldIndex = !stopSearchEngineIndexing;
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-styles.css');
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-assets/hydrogen-styles.css');
const stylesUrl = urlJoin(basePath, '/css/styles.css');
const roomDirectoryStylesUrl = urlJoin(basePath, '/css/room-directory.css');
const jsBundleUrl = urlJoin(basePath, '/js/entry-client-room-directory.es.js');

View File

@ -865,7 +865,7 @@ router.get(
shouldIndex = roomData?.historyVisibility === `world_readable`;
}
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-styles.css');
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-assets/hydrogen-styles.css');
const stylesUrl = urlJoin(basePath, '/css/styles.css');
const jsBundleUrl = urlJoin(basePath, '/js/entry-client-hydrogen.es.js');

View File

@ -50,7 +50,7 @@ async function timeoutMiddleware(req, res, next) {
const cspNonce = res.locals.cspNonce;
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-styles.css');
const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-assets/hydrogen-styles.css');
const stylesUrl = urlJoin(basePath, '/css/styles.css');
const pageHtml = `