azion
Version:
Azion Packages for Edge Computing.
2 lines (1 loc) • 2.58 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={IMAGES:["jpg","jpeg","png","gif","bmp","webp","svg","ico"],FONTS:["ttf","otf","woff","woff2","eot"],DOCUMENTS:["pdf","doc","docx","xls","xlsx","ppt","pptx"],MEDIA:["mp4","webm","mp3","wav","ogg"],CODE_AND_DATA:["css","js","json","xml","html","txt","csv"],ARCHIVES:["zip","rar","7z","tar","gz"],OTHER:["webmanifest","map","md","yaml","yml"]},o=[...e.IMAGES,...e.FONTS,...e.DOCUMENTS,...e.MEDIA,...e.CODE_AND_DATA,...e.ARCHIVES,...e.OTHER];function n(i={}){const{connector:t="name-connector",application:r="name-application",staticExtensions:a=o}=i;return{request:[{name:"Deliver Static Assets and Set Cache Policy",description:"Deliver static assets directly from storage and set cache policy",active:!0,criteria:[[{variable:"${uri}",conditional:"if",operator:"matches",argument:`\\.(${a.join("|")})$`}]],behaviors:[{type:"set_connector",attributes:{value:t}},{type:"set_cache_policy",attributes:{value:r}},{type:"deliver"}]},{name:"Redirect to index.html",description:"Handle directory requests by rewriting to index.html",active:!0,criteria:[[{variable:"${uri}",conditional:"if",operator:"matches",argument:".*/$"}]],behaviors:[{type:"set_connector",attributes:{value:t}},{type:"rewrite_request",attributes:{value:"${uri}index.html"}}]},{name:"Redirect to index.html for Subpaths",description:"Handle subpath requests by rewriting to index.html",active:!0,criteria:[[{variable:"${uri}",conditional:"if",operator:"matches",argument:"^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*"}]],behaviors:[{type:"set_connector",attributes:{value:t}},{type:"rewrite_request",attributes:{value:"${uri}/index.html"}}]}],response:[]}}function c(i={}){const{connector:t="name-connector",application:r="name-application",staticExtensions:a=o}=i;return{request:[{name:"Deliver Static Assets and Set Cache Policy",description:"Deliver static assets directly from storage and set cache policy",active:!0,criteria:[[{variable:"${uri}",conditional:"if",operator:"matches",argument:`\\.(${a.join("|")})$`}]],behaviors:[{type:"set_connector",attributes:{value:t}},{type:"set_cache_policy",attributes:{value:r}},{type:"deliver"}]},{name:"Redirect to index.html",description:"Handle all routes by rewriting to index.html for client-side routing",active:!0,criteria:[[{variable:"${uri}",conditional:"if",operator:"matches",argument:"^\\/"}]],behaviors:[{type:"set_connector",attributes:{value:t}},{type:"rewrite_request",attributes:{value:"/index.html"}}]}],response:[]}}exports.createMPARules=n;exports.createSPARules=c;