Skip to content

Commit

Permalink
Merge pull request #2369 from easyops-cn/steve/runtime-standalone
Browse files Browse the repository at this point in the history
fix(): merge settings in standalone mode
  • Loading branch information
qiaofengxi committed Nov 2, 2022
2 parents 430d0ef + 6579db3 commit 5d1cdb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/brick-container/serve/getProxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
getDevSettings,
appendLiveReloadScript,
tryFiles,
removeCacheHeaders,
} = require("./utils");

module.exports = (env) => {
Expand Down Expand Up @@ -99,7 +100,10 @@ module.exports = (env) => {
}

if (reqIsBootstrap) {
console.log("Modified bootstrap:", req.path);
if (matchedStandaloneConfig && res.statusCode === 200) {
// Disable cache for standalone bootstrap for development.
removeCacheHeaders(proxyRes);
}
modifyResponse(res, proxyRes, (raw) => {
if (res.statusCode !== 200) {
return raw;
Expand Down Expand Up @@ -194,7 +198,6 @@ module.exports = (env) => {
if (res.statusCode !== 200) {
return raw;
}

const result = JSON.parse(raw);
const { data } = result;
if (useDarkThemeApps.includes(data.app.id)) {
Expand Down Expand Up @@ -325,6 +328,33 @@ module.exports = (env) => {
}
);
}
} else if (
req.path === "/next/api/v1/runtime_standalone" ||
req.path === "/api/v1/runtime_standalone"
) {
if (res.statusCode === 200) {
// Disable cache for standalone runtime for development.
removeCacheHeaders(proxyRes);
}
modifyResponse(res, proxyRes, (raw) => {
if (res.statusCode !== 200) {
return raw;
}
const result = JSON.parse(raw);
const { data } = result;
if (useLocalSettings) {
data.settings = getSettings(env);
} else {
data.settings = mergeSettings(data.settings, getDevSettings());
if (useMergeSettings) {
data.settings = mergeSettings(
data.settings,
getUserSettings(env)
);
}
}
return JSON.stringify(result);
});
}
};
}
Expand Down
8 changes: 8 additions & 0 deletions packages/brick-container/serve/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ function appendLiveReloadScript(raw, env) {
);
}

function removeCacheHeaders(proxyRes) {
delete proxyRes.headers["cache-control"];
delete proxyRes.headers["expires"];
delete proxyRes.headers["etag"];
delete proxyRes.headers["last-modified"];
}

exports.getNavbar = getNavbar;
exports.getStoryboardsByMicroApps = getStoryboardsByMicroApps;
exports.getSingleStoryboard = getSingleStoryboard;
Expand All @@ -409,3 +416,4 @@ exports.checkLocalPackages = checkLocalPackages;
exports.tryFiles = tryFiles;
exports.tryServeFiles = tryServeFiles;
exports.appendLiveReloadScript = appendLiveReloadScript;
exports.removeCacheHeaders = removeCacheHeaders;

0 comments on commit 5d1cdb8

Please sign in to comment.