Skip to content

Commit f948ab8

Browse files
committed
feat: avoid cache on added projects
1 parent 7f14dfd commit f948ab8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/extension/auth.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import { ADMIN_ORIGIN, ADMIN_ORIGIN_NEW } from './utils/admin.js';
1919
const { host: adminHost } = new URL(ADMIN_ORIGIN);
2020
const { host: newAdminHost } = new URL(ADMIN_ORIGIN_NEW);
2121

22-
/** Cache-Control max-age in seconds for added project hosts (HTML, JSON and code): 1 minute. */
23-
export const CACHE_MAX_AGE_SECONDS = 60;
24-
2522
function getRandomId() {
2623
return Math.floor(Math.random() * 1000000);
2724
}
@@ -59,10 +56,14 @@ export function getCacheControlRules(projectConfigs) {
5956
priority: 1,
6057
action: {
6158
type: 'modifyHeaders',
62-
responseHeaders: [{
59+
requestHeaders: [{
60+
operation: 'set',
6361
header: 'Cache-Control',
62+
value: 'no-cache',
63+
}, {
6464
operation: 'set',
65-
value: `max-age=${CACHE_MAX_AGE_SECONDS}, must-revalidate`,
65+
header: 'Pragma',
66+
value: 'no-cache',
6667
}],
6768
},
6869
condition: {

test/auth.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { setUserAgent } from '@web/test-runner-commands';
1818
import sinon from 'sinon';
1919

2020
import {
21-
CACHE_MAX_AGE_SECONDS,
2221
configureAuthAndCorsHeaders,
2322
getCacheControlRules,
2423
getHostDomain,
@@ -82,8 +81,8 @@ describe('Test auth', () => {
8281
];
8382
const rules = getCacheControlRules(configs);
8483
expect(rules).to.have.lengthOf(2);
85-
expect(rules.every((r) => r.action?.responseHeaders?.[0]?.header === 'Cache-Control')).to.be.true;
86-
expect(rules.every((r) => r.action.responseHeaders[0].value === `max-age=${CACHE_MAX_AGE_SECONDS}, must-revalidate`)).to.be.true;
84+
expect(rules.every((r) => r.action?.requestHeaders?.some((h) => h.header === 'Cache-Control' && h.value === 'no-cache'))).to.be.true;
85+
expect(rules.every((r) => r.action?.requestHeaders?.some((h) => h.header === 'Pragma' && h.value === 'no-cache'))).to.be.true;
8786
const filters = rules.map((r) => r.condition.regexFilter);
8887
expect(filters).to.include('^https://prod\\.example\\.com/.*');
8988
expect(filters).to.include('^https://live\\.example\\.com/.*');

0 commit comments

Comments
 (0)