UNPKG

azion

Version:

Azion Packages for Edge Computing.

196 lines (195 loc) 4.62 kB
const e = { // Images IMAGES: ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico"], // Fonts FONTS: ["ttf", "otf", "woff", "woff2", "eot"], // Documents DOCUMENTS: ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx"], // Media MEDIA: ["mp4", "webm", "mp3", "wav", "ogg"], // Code & Data CODE_AND_DATA: ["css", "js", "json", "xml", "html", "txt", "csv"], // Archives ARCHIVES: ["zip", "rar", "7z", "tar", "gz"], // Other 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: [] }; } export { n as createMPARules, c as createSPARules };