Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle assethost based on type #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions server/handlers/generate-service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ async function generateServiceWorker(
}
) {
const configVersion = await maxConfigVersion(config, domainSlug);
const customAssetHelper = typeof assetHelper === 'function' && Object.keys(config).length > 0 ? assetHelper(config) : assetHelper;

return new Promise((resolve) => {
renderServiceWorker(
res,
"js/service-worker",
{
config,
serviceWorkerHelper: assetHelper.serviceWorkerContents(),
assetPath: assetHelper.assetPath,
serviceWorkerHelper: customAssetHelper.serviceWorkerContents(),
assetPath: customAssetHelper.assetPath,
hostname: req.hostname,
assetHash: assetHelper.assetHash,
assetHash: customAssetHelper.assetHash,
configVersion,
getFilesForChunks: assetHelper.getFilesForChunks,
getFilesForChunks: customAssetHelper.getFilesForChunks,
routes: generateRoutes(config, domainSlug).filter(
(route) => !route.skipPWA
),
Expand Down
8 changes: 5 additions & 3 deletions server/handlers/isomorphic-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ exports.handleIsomorphicShell = async function handleIsomorphicShell(
}
) {
const url = urlLib.parse(req.url, true);
const freshRevision = `${assetHelper.assetHash("app.js")}-${await maxConfigVersion(config, domainSlug)}`;
const customAssetHelper = typeof assetHelper === 'function' && Object.keys(config).length > 0 ? assetHelper(config) : assetHelper;
const freshRevision = `${customAssetHelper.assetHash("app.js")}-${await maxConfigVersion(config, domainSlug)}`;

if (req.query.revision && req.query.revision !== freshRevision)
return res.status(503).send("Requested Shell Is Not Current");
Expand All @@ -144,7 +145,7 @@ exports.handleIsomorphicShell = async function handleIsomorphicShell(
res.setHeader("Vary", "Accept-Encoding");

if (preloadJs) {
res.append("Link", `<${assetHelper.assetPath("app.js")}>; rel=preload; as=script;`);
res.append("Link", `<${customAssetHelper.assetPath("app.js")}>; rel=preload; as=script;`);
}
const seoInstance = getSeoInstance(seo, config, "shell");
const seoTags = seoInstance && seoInstance.getMetaTags(config, "shell", result, { url });
Expand Down Expand Up @@ -430,6 +431,7 @@ exports.handleIsomorphicRoute = function handleIsomorphicRoute(
}
) {
const url = urlLib.parse(req.url, true);
const customAssetHelper = typeof assetHelper === 'function' && Object.keys(config).length > 0 ? assetHelper(config) : assetHelper;

function writeResponse(result) {
const statusCode = result.httpStatusCode || 200;
Expand Down Expand Up @@ -473,7 +475,7 @@ exports.handleIsomorphicRoute = function handleIsomorphicRoute(
});

if (preloadJs) {
res.append("Link", `<${assetHelper.assetPath("app.js")}>; rel=preload; as=script;`);
res.append("Link", `<${customAssetHelper.assetPath("app.js")}>; rel=preload; as=script;`);
}
const oneSignalScript = oneSignalServiceWorkers ? getOneSignalScript({ config, publisherConfig }) : null;
return pickComponent.preloadComponent(store.getState().qt.pageType, store.getState().qt.subPageType).then(() =>
Expand Down