@void/edge 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +23 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,10 @@ type ProjectZeroTrustRouting = Readonly<{
|
|
|
8
8
|
}>>;
|
|
9
9
|
}>;
|
|
10
10
|
//#endregion
|
|
11
|
+
//#region src/https.d.ts
|
|
12
|
+
/** Upgrade public HTTP requests without involving assets or application code. */
|
|
13
|
+
export declare function redirectToHttps(request: Request): Response | undefined;
|
|
14
|
+
//#endregion
|
|
11
15
|
//#region src/headers.d.ts
|
|
12
16
|
type HeaderRulePolicy = Readonly<{
|
|
13
17
|
/**
|
|
@@ -156,6 +160,7 @@ type StaticEdgeEnv = Readonly<{
|
|
|
156
160
|
ASSETS: EdgeAssetFetcher;
|
|
157
161
|
}>;
|
|
158
162
|
type StaticEdgeConfig = Readonly<{
|
|
163
|
+
alwaysUseHttps?: boolean;
|
|
159
164
|
/** Optional native Worker self-metadata used to identify the served version. */
|
|
160
165
|
versionMetadataBinding?: string;
|
|
161
166
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
//#region src/https.ts
|
|
2
|
+
/** Upgrade public HTTP requests without involving assets or application code. */
|
|
3
|
+
function redirectToHttps(request) {
|
|
4
|
+
const url = new URL(request.url);
|
|
5
|
+
if (url.protocol !== "http:" || url.hostname === "localhost" || url.hostname.endsWith(".localhost") || isIpv4Loopback(url.hostname) || url.hostname === "[::1]" || url.pathname.startsWith("/.well-known/acme-challenge/") || url.pathname.startsWith("/.well-known/pki-validation/")) return;
|
|
6
|
+
url.protocol = "https:";
|
|
7
|
+
url.port = "";
|
|
8
|
+
return Response.redirect(url.href, 308);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* `URL` already rewrites every IPv4 form (`127.1`, `0x7f.0.0.1`) to four
|
|
12
|
+
* decimal parts and rejects parts above 255, so only the shape is checked.
|
|
13
|
+
*/
|
|
14
|
+
function isIpv4Loopback(hostname) {
|
|
15
|
+
const parts = hostname.split(".");
|
|
16
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((part) => part !== "" && [...part].every((char) => char >= "0" && char <= "9"));
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
1
19
|
//#region src/pattern.ts
|
|
2
20
|
/**
|
|
3
21
|
* Path-pattern matchers shared by routing, header, and revalidate rules.
|
|
@@ -564,6 +582,10 @@ function createStaticEdgeHandler(config) {
|
|
|
564
582
|
versionId: metadata?.id
|
|
565
583
|
}, { headers: { "cache-control": "no-store" } });
|
|
566
584
|
}
|
|
585
|
+
if (config.alwaysUseHttps) {
|
|
586
|
+
const redirect = redirectToHttps(request);
|
|
587
|
+
if (redirect) return redirect;
|
|
588
|
+
}
|
|
567
589
|
let effectiveUrl = new URL(originalUrl);
|
|
568
590
|
let effectiveRequest = request;
|
|
569
591
|
const route = applyRoutingRules(effectiveUrl.pathname, config.redirectRules, effectiveUrl.hostname);
|
|
@@ -864,4 +886,4 @@ function usageLimitResponse(limit) {
|
|
|
864
886
|
});
|
|
865
887
|
}
|
|
866
888
|
//#endregion
|
|
867
|
-
export { applyHeaderRules, applyRoutingRules, compilePattern, createStaticEdgeHandler, getContentType, matchLiteralPattern, matchPattern, matchPatternCaptures, matchSegmentPattern, mergeQueryIntoLocation, parseClearSiteData, readUsageLimit, resolveAssetContentType, resolveStaticPath, safeDecodePathname, sanitizeClearSiteData, substituteParams, usageLimitResponse };
|
|
889
|
+
export { applyHeaderRules, applyRoutingRules, compilePattern, createStaticEdgeHandler, getContentType, matchLiteralPattern, matchPattern, matchPatternCaptures, matchSegmentPattern, mergeQueryIntoLocation, parseClearSiteData, readUsageLimit, redirectToHttps, resolveAssetContentType, resolveStaticPath, safeDecodePathname, sanitizeClearSiteData, substituteParams, usageLimitResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/edge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Routing, headers, and static asset helpers for Void runtimes.",
|
|
5
5
|
"homepage": "https://void.cloud",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@void/deploy-core": "1.
|
|
29
|
+
"@void/deploy-core": "1.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@cloudflare/workers-types": "^5.20261019.1",
|