File tree Expand file tree Collapse file tree 1 file changed +38
-40
lines changed
Expand file tree Collapse file tree 1 file changed +38
-40
lines changed Original file line number Diff line number Diff line change @@ -43,47 +43,45 @@ export function getHostDomain(host) {
4343 */
4444export function getCacheControlRules ( projectConfigs ) {
4545 const rules = [ ] ;
46- const hosts = [
47- ...new Set (
48- projectConfigs
49- . flatMap ( ( p ) => [
50- p ?. host ,
51- p ?. previewHost ,
52- p ?. liveHost ,
53- p ?. reviewHost ,
54- ] . filter ( Boolean ) . map ( getHostDomain ) ) ,
55- ) ,
56- ] . filter ( Boolean ) ;
57- hosts . forEach ( ( domain ) => {
58- const escaped = domain . replaceAll ( / \. / g, '\\.' ) ;
59- rules . push ( {
60- id : getRandomId ( ) ,
61- priority : 1 ,
62- action : {
63- type : 'modifyHeaders' ,
64- responseHeaders : [ {
65- header : 'Cache-Control' ,
66- operation : 'set' ,
67- value : `max-age=${ CACHE_MAX_AGE_SECONDS } ` ,
68- } ] ,
69- } ,
70- condition : {
71- regexFilter : `^https://${ escaped } /.*` ,
72- requestMethods : [ 'get' ] ,
73- resourceTypes : [
74- 'main_frame' ,
75- 'sub_frame' ,
76- 'script' ,
77- 'stylesheet' ,
78- 'image' ,
79- 'xmlhttprequest' ,
80- 'media' ,
81- 'font' ,
82- 'other' ,
83- ] ,
84- } ,
46+ projectConfigs
47+ . flatMap ( ( p ) => [
48+ p ?. host ,
49+ p ?. previewHost ,
50+ p ?. liveHost ,
51+ p ?. reviewHost ,
52+ ] . filter ( Boolean ) . map ( getHostDomain ) )
53+ . filter ( Boolean )
54+ . filter ( ( domain , i , self ) => self . indexOf ( domain ) === i )
55+ . forEach ( ( domain ) => {
56+ const escaped = domain . replaceAll ( / \. / g, '\\.' ) ;
57+ rules . push ( {
58+ id : getRandomId ( ) ,
59+ priority : 1 ,
60+ action : {
61+ type : 'modifyHeaders' ,
62+ responseHeaders : [ {
63+ header : 'Cache-Control' ,
64+ operation : 'set' ,
65+ value : `max-age=${ CACHE_MAX_AGE_SECONDS } ` ,
66+ } ] ,
67+ } ,
68+ condition : {
69+ regexFilter : `^https://${ escaped } /.*` ,
70+ requestMethods : [ 'get' ] ,
71+ resourceTypes : [
72+ 'main_frame' ,
73+ 'sub_frame' ,
74+ 'script' ,
75+ 'stylesheet' ,
76+ 'image' ,
77+ 'xmlhttprequest' ,
78+ 'media' ,
79+ 'font' ,
80+ 'other' ,
81+ ] ,
82+ } ,
83+ } ) ;
8584 } ) ;
86- } ) ;
8785 return rules ;
8886}
8987
You can’t perform that action at this time.
0 commit comments