@aryanbansal-launch/edge-utils 0.1.7 β 0.1.8
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/launch/config.js +0 -3
- package/package.json +1 -1
- package/readme.md +17 -11
package/dist/launch/config.js
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# π Edge Utils for Contentstack Launch
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@aryanbansal-launch/edge-utils)
|
|
3
|
+
[](https://www.npmjs.com/package/@aryanbansal-launch/edge-utils)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
6
|
A lightweight, high-performance toolkit specifically designed for **Contentstack Launch Edge Functions**. Speed up your development with production-ready utilities for security, authentication, routing, and Next.js compatibilityβall optimized to run at the edge.
|
|
@@ -36,7 +36,7 @@ npx launch-init
|
|
|
36
36
|
This will automatically create the `functions/` directory and a boilerplate `[proxy].edge.js` handler for you.
|
|
37
37
|
|
|
38
38
|
### 3. Configure (Optional)
|
|
39
|
-
Manage your `launch.json` (Redirects, Rewrites, and Cache Priming) interactively:
|
|
39
|
+
Manage your `launch.json` ([Redirects](https://www.contentstack.com/docs/developers/launch/edge-url-redirects), [Rewrites](https://www.contentstack.com/docs/developers/launch/edge-url-rewrites), and [Cache Priming](https://www.contentstack.com/docs/developers/launch/cache-priming)) interactively:
|
|
40
40
|
```bash
|
|
41
41
|
npx launch-config
|
|
42
42
|
```
|
|
@@ -71,15 +71,15 @@ export default async function handler(request, context) {
|
|
|
71
71
|
});
|
|
72
72
|
if (rscResponse) return rscResponse;
|
|
73
73
|
|
|
74
|
-
//
|
|
74
|
+
// 3. π€ Block AI bots immediately
|
|
75
75
|
const botResponse = blockAICrawlers(request);
|
|
76
76
|
if (botResponse) return botResponse;
|
|
77
77
|
|
|
78
|
-
//
|
|
78
|
+
// 4. π§± IP Whitelisting
|
|
79
79
|
const ipResponse = ipAccessControl(request, { allow: ["203.0.113.10"] });
|
|
80
80
|
if (ipResponse) return ipResponse;
|
|
81
81
|
|
|
82
|
-
//
|
|
82
|
+
// 5. π Domain-specific Basic Auth (e.g., for staging)
|
|
83
83
|
const authResponse = await protectWithBasicAuth(request, {
|
|
84
84
|
hostnameIncludes: "staging.myapp.com",
|
|
85
85
|
username: "admin",
|
|
@@ -87,7 +87,7 @@ export default async function handler(request, context) {
|
|
|
87
87
|
});
|
|
88
88
|
if (authResponse && authResponse.status === 401) return authResponse;
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// 6. π SEO-friendly Redirects
|
|
91
91
|
const redirectResponse = redirectIfMatch(request, {
|
|
92
92
|
path: "/legacy-url",
|
|
93
93
|
to: "/modern-url",
|
|
@@ -95,11 +95,11 @@ export default async function handler(request, context) {
|
|
|
95
95
|
});
|
|
96
96
|
if (redirectResponse) return redirectResponse;
|
|
97
97
|
|
|
98
|
-
//
|
|
98
|
+
// 7. π Geo-Location Access
|
|
99
99
|
const geo = getGeoHeaders(request);
|
|
100
100
|
console.log(`Request from ${geo.city}, ${geo.country}`);
|
|
101
101
|
|
|
102
|
-
//
|
|
102
|
+
// 8. π Pass through to origin
|
|
103
103
|
return passThrough(request);
|
|
104
104
|
}
|
|
105
105
|
```
|
|
@@ -109,9 +109,9 @@ export default async function handler(request, context) {
|
|
|
109
109
|
## π API Reference
|
|
110
110
|
|
|
111
111
|
### π‘οΈ Security
|
|
112
|
-
- **`blockAICrawlers(request, bots?)`**:
|
|
113
|
-
- **`blockDefaultDomains(request, { domainToBlock? })`**:
|
|
114
|
-
- **`ipAccessControl(request, { allow?, deny? })`**:
|
|
112
|
+
- **`blockAICrawlers(request, bots?)`**: Detects and blocks known AI crawlers (GPTBot, ClaudeBot, etc.) based on the User-Agent.
|
|
113
|
+
- **`blockDefaultDomains(request, { domainToBlock? })`**: Prevents users from accessing your site via the default `*.contentstackapps.com` domains, forcing them to use your custom domain.
|
|
114
|
+
- **`ipAccessControl(request, { allow?, deny? })`**: A simple firewall to whitelist or blacklist specific IP addresses at the edge.
|
|
115
115
|
|
|
116
116
|
### π Authentication
|
|
117
117
|
- **`protectWithBasicAuth(request, options)`**: Prompt for credentials based on hostname.
|
|
@@ -130,3 +130,9 @@ export default async function handler(request, context) {
|
|
|
130
130
|
## π Platform Support
|
|
131
131
|
|
|
132
132
|
This library is exclusively optimized for **[Contentstack Launch](https://www.contentstack.com/docs/developers/launch)**.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## π License
|
|
137
|
+
|
|
138
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|