@stacksjs/server 0.74.36 → 0.74.38
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.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/rewrites.d.ts +29 -0
- package/dist/rewrites.js +1 -0
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{config as server}from"./config";export*from"./controllers/base";export*from"./imports";export*from"./maintenance";export*from"./proxy";export*from"./redirects";export*from"./security-headers";
|
|
1
|
+
export{config as server}from"./config";export*from"./controllers/base";export*from"./imports";export*from"./maintenance";export*from"./proxy";export*from"./redirects";export*from"./rewrites";export*from"./security-headers";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise app configuration into the map the resolver reads.
|
|
3
|
+
*
|
|
4
|
+
* Resolved once at boot, for the same reason the redirect table is: config
|
|
5
|
+
* overrides arrive asynchronously, so a per-request read answers differently
|
|
6
|
+
* depending on how far boot has got.
|
|
7
|
+
*
|
|
8
|
+
* Invalid entries are dropped rather than thrown on — a malformed rewrite must
|
|
9
|
+
* not stop a site booting — and so is a rule that rewrites a path to itself,
|
|
10
|
+
* which would otherwise proxy the views server to the API and back.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveRewriteRules(input?: RewriteConfig): RewriteRules;
|
|
13
|
+
/**
|
|
14
|
+
* The path to ask the API for, or undefined when nothing matches.
|
|
15
|
+
*
|
|
16
|
+
* An exact rule always wins over a prefix one, and the longest prefix wins
|
|
17
|
+
* among those — so a specific path can be carved out of a subtree that is
|
|
18
|
+
* otherwise rewritten wholesale.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveRewrite(pathname: string, rules?: RewriteRules): string | undefined;
|
|
21
|
+
/** A one-line summary for the dev server's boot output. */
|
|
22
|
+
export declare function describeRewriteRules(rules: RewriteRules): string;
|
|
23
|
+
export declare interface RewriteRule {
|
|
24
|
+
from: string
|
|
25
|
+
to: string
|
|
26
|
+
prefix: boolean
|
|
27
|
+
}
|
|
28
|
+
export type RewriteRules = Map<string, RewriteRule>;
|
|
29
|
+
export type RewriteConfig = Record<string, string>;
|
package/dist/rewrites.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const PROTECTED_PREFIX="/api/";function normalizePath(value){const path=String(value).trim();if(!path.startsWith("/"))return"";return path.length>1&&path.endsWith("/")?path.replace(/\/+$/,""):path}export function resolveRewriteRules(input={}){const rules=new Map;for(const[rawFrom,rawTo]of Object.entries(input??{})){const prefix=rawFrom.endsWith("*"),from=normalizePath(prefix?rawFrom.slice(0,-1):rawFrom);if(!from)continue;if(from===PROTECTED_PREFIX.slice(0,-1)||from.startsWith(PROTECTED_PREFIX))continue;const to=normalizePath(prefix&&rawTo.endsWith("*")?rawTo.slice(0,-1):rawTo);if(!to||to===from)continue;rules.set(from,{from,to,prefix})}return rules}export function resolveRewrite(pathname,rules){if(!rules||rules.size===0)return;const path=normalizePath(pathname);if(!path)return;const exact=rules.get(path);if(exact&&!exact.prefix)return exact.to;let best;for(const rule of rules.values()){if(!rule.prefix||!path.startsWith(rule.from))continue;if(!best||rule.from.length>best.from.length)best=rule}if(!best)return;return`${best.to}${path.slice(best.from.length)}`}export function describeRewriteRules(rules){if(!rules||rules.size===0)return"";return[...rules.values()].map((rule)=>`${rule.from}${rule.prefix?"*":""} \u2192 ${rule.to}${rule.prefix?"*":""}`).join(", ")}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/server",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.38",
|
|
6
6
|
"description": "Local development and production-ready.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
"prepublishOnly": "bun run build"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@stacksjs/auth": "0.74.
|
|
62
|
-
"@stacksjs/config": "0.74.
|
|
63
|
-
"@stacksjs/events": "0.74.
|
|
64
|
-
"@stacksjs/i18n": "0.74.
|
|
65
|
-
"@stacksjs/logging": "0.74.
|
|
66
|
-
"@stacksjs/orm": "0.74.
|
|
67
|
-
"@stacksjs/path": "0.74.
|
|
68
|
-
"@stacksjs/router": "0.74.
|
|
69
|
-
"@stacksjs/storage": "0.74.
|
|
61
|
+
"@stacksjs/auth": "0.74.38",
|
|
62
|
+
"@stacksjs/config": "0.74.38",
|
|
63
|
+
"@stacksjs/events": "0.74.38",
|
|
64
|
+
"@stacksjs/i18n": "0.74.38",
|
|
65
|
+
"@stacksjs/logging": "0.74.38",
|
|
66
|
+
"@stacksjs/orm": "0.74.38",
|
|
67
|
+
"@stacksjs/path": "0.74.38",
|
|
68
|
+
"@stacksjs/router": "0.74.38",
|
|
69
|
+
"@stacksjs/storage": "0.74.38",
|
|
70
70
|
"bun-plugin-auto-imports": "^0.4.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@stacksjs/validation": "0.74.
|
|
73
|
+
"@stacksjs/validation": "0.74.38",
|
|
74
74
|
"better-dx": "^0.2.24"
|
|
75
75
|
}
|
|
76
76
|
}
|