Skip to content

Commit

Permalink
fix: avoid log error in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Apr 9, 2020
1 parent 7228817 commit 8f16f11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/subapp-web/lib/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ module.exports = function setup(setupContext, { props: setupProps }) {
const retrieveDevServerBundle = async () => {
return new Promise(resolve => {
const routeOptions = setupContext.routeOptions;
const path = `${bundleBase}${bundleAsset.name}`;
const path = Path.posix.join(bundleBase, bundleAsset.name);
const bundleUrl = formUrl({ ...routeOptions.httpDevServer, path });
retrieveUrl(bundleUrl, (err, resp, body) => {
if (err || resp.statusCode !== 200) {
const msg = makeDevDebugMessage(
`Error: fail to retrieve subapp bundle from '${bundleUrl}' for inlining in index HTML
${err || body}`
Response: ${err || body}`
);
console.error(msg); // eslint-disable-line
resolve(makeDevDebugHtml(msg));
Expand Down
26 changes: 23 additions & 3 deletions packages/subapp-web/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,32 @@ const utils = {
return CDN_JS_BUNDLES;
}

if (routeOptions.cdn.enable !== false && CDN_ASSETS === undefined) {
if (routeOptions.cdn.enable === true && CDN_ASSETS === undefined) {
const env = process.env.NODE_ENV;
const prod = env === "production";
const ignoreMsg = `== This is OK and you can ignore this message if it's what you intended. ==`;
const logError = console.error; // eslint-disable-line
if (!prod) {
logError(
`Warning: you've set cdn.enable to true for NODE_ENV ${env}.
Generally you should do that for production deployment in the cloud only.
${ignoreMsg}`
);
}

try {
const assetsFp = Path.resolve(cdnAssetsFile);
CDN_ASSETS = require(assetsFp);
CDN_ASSETS = JSON.parse(Fs.readFileSync(assetsFp));
} catch (err) {
console.error("Error: Loading CDN assets map failed", err); // eslint-disable-line
if (prod) {
logError("Error: Loading CDN assets map failed", err); // eslint-disable-line
} else {
logError(
`Warning: load CDN asset map failed, default to local assets for NODE_ENV ${env} mode. path: ${cdnAssetsFile}
Error: ${err.message}
${ignoreMsg}`
);
}
CDN_ASSETS = false;
}
}
Expand Down

0 comments on commit 8f16f11

Please sign in to comment.