Skip to content

Commit

Permalink
Disable caching in preview server (#6553)
Browse files Browse the repository at this point in the history
* Useful in case the preview is proxied through a CDN

Only show in developer changelog
  • Loading branch information
arthuro555 committed May 5, 2024
1 parent b7a4bab commit 1e87b74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions newIDE/electron-app/app/ServeFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const liveServer = require('live-server');
const httpsConfiguration = require('./Utils/DevServerHttpsConfiguration.js');
const { getAvailablePort } = require('./Utils/AvailablePortFinder');

/** @type {import("live-server").LiveServerParams} */
let currentServerParams = null;

module.exports = {
Expand All @@ -27,6 +28,21 @@ module.exports = {
// the hot-reloading built into the game engine is what should
// be used - and the user can still reload manually on its browser.
watch: [],
middleware: [
// Disable caching, as it can lead to older generated code being served
// in case preview files are proxied through a CDN (see
// https://github.com/4ian/GDevelop/pull/6553 for example)
function noCache(_, res, next) {
res.setHeader('Surrogate-Control', 'no-store');
res.setHeader(
'Cache-Control',
'no-store, no-cache, must-revalidate, proxy-revalidate'
);
res.setHeader('Expires', '0');

next();
},
],
};
liveServer.start(currentServerParams);
onDone(null, currentServerParams);
Expand Down
5 changes: 4 additions & 1 deletion newIDE/electron-app/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ app.on('ready', function() {
log.info('Received event to server folder with options=', options);

serveFolder(options, (err, serverParams) => {
event.sender.send('serve-folder-done', err, serverParams);
// Using JSON to copy the config strips unserializable properties
// (like middleware functions) automatically.
const configCopy = JSON.parse(JSON.stringify(serverParams));
event.sender.send('serve-folder-done', err, configCopy);
});
});

Expand Down

0 comments on commit 1e87b74

Please sign in to comment.