create-acrylblends 0.4.0 → 1.0.0-rc.1
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/README.md +4 -2
- package/dist/index.d.ts +10 -1
- package/dist/index.js +37 -16
- package/dist/index.js.map +1 -1
- package/docs/framework/README.md +5 -3
- package/docs/framework/agents/index.md +1 -1
- package/docs/framework/api/acryl.md +3 -3
- package/docs/framework/api/summary.md +1 -1
- package/docs/framework/concepts/web-standard.md +4 -14
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +13 -8
- package/docs/framework/cordis/migration-from-0-4.md +1 -1
- package/docs/framework/cordis/migration-to-1-0.md +45 -0
- package/docs/framework/cordis/node-server.md +27 -5
- package/docs/framework/getting-started/basic.md +15 -10
- package/docs/framework/getting-started/desktop.md +1 -1
- package/docs/framework/getting-started/other-runtimes.md +10 -14
- package/docs/framework/guides/create-acrylblends.md +4 -2
- package/docs/framework/guides/data.md +1 -1
- package/docs/framework/guides/faq.md +1 -1
- package/docs/framework/guides/production.md +43 -0
- package/docs/framework/helpers/conninfo.md +1 -36
- package/docs/framework/helpers/websocket.md +4 -11
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/middleware/builtin/loopback-only.md +1 -1
- package/package.json +2 -2
- package/docs/framework/getting-started/aws-lambda.md +0 -115
- package/docs/framework/getting-started/cloudflare-pages.md +0 -53
- package/docs/framework/getting-started/cloudflare-workers.md +0 -67
- package/docs/framework/getting-started/lambda-edge.md +0 -41
- package/docs/framework/getting-started/netlify.md +0 -25
- package/docs/framework/getting-started/service-worker.md +0 -33
- package/docs/framework/getting-started/vercel.md +0 -28
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Lambda@Edge
|
|
2
|
-
|
|
3
|
-
An Acryl app can answer CloudFront requests from Lambda@Edge. `handle(app)` from `acrylblends/lambda-edge` turns the app into the edge function: it builds a `Request` from the CloudFront event, calls `app.fetch`, and returns a CloudFront response. A viewer-request or origin-request function that answers by itself (a redirect, an HTML page, a JSON answer) is the typical use.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a CloudFront viewer-request event. It has not been deployed to AWS by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Acryl } from 'acrylblends'
|
|
9
|
-
import { handle } from 'acrylblends/lambda-edge'
|
|
10
|
-
|
|
11
|
-
const app = new Acryl()
|
|
12
|
-
|
|
13
|
-
app.get('/', (c) => c.text('Hello from the edge'))
|
|
14
|
-
|
|
15
|
-
export const handler = handle(app)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Lambda@Edge has its own limits: the function must be created in `us-east-1`, has no environment variables, and its size and time limits are lower than Lambda's; check them in the AWS documentation when you choose between this adapter and [AWS Lambda](aws-lambda.md).
|
|
19
|
-
|
|
20
|
-
## The CloudFront event
|
|
21
|
-
|
|
22
|
-
The CloudFront request, response and config are in the bindings:
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { Acryl } from 'acrylblends'
|
|
26
|
-
import type { Callback, CloudFrontEdgeEvent } from 'acrylblends/lambda-edge'
|
|
27
|
-
|
|
28
|
-
type Bindings = {
|
|
29
|
-
callback: Callback
|
|
30
|
-
event: CloudFrontEdgeEvent
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const app = new Acryl<{ Bindings: Bindings }>()
|
|
34
|
-
|
|
35
|
-
app.get('/country', (c) => {
|
|
36
|
-
const request = c.env.event.Records[0].cf.request
|
|
37
|
-
return c.json({ uri: request.uri, clientIp: request.clientIp })
|
|
38
|
-
})
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The client's address is available through the [ConnInfo helper](../helpers/conninfo.md).
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Netlify
|
|
2
|
-
|
|
3
|
-
Netlify Functions (version 2) and Edge Functions take a `Request` and a context and return a `Response`. `handle(app)` from `acrylblends/netlify` is that function; the Netlify context is available to the app as `c.env.context`.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a `Request`. It has not been deployed to Netlify by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
## A function
|
|
8
|
-
|
|
9
|
-
`netlify/functions/api.ts`:
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { Acryl } from 'acrylblends'
|
|
13
|
-
import { handle } from 'acrylblends/netlify'
|
|
14
|
-
import type { Context } from '@netlify/functions'
|
|
15
|
-
|
|
16
|
-
type Bindings = { context: Context }
|
|
17
|
-
|
|
18
|
-
const app = new Acryl<{ Bindings: Bindings }>().basePath('/.netlify/functions/api')
|
|
19
|
-
|
|
20
|
-
app.get('/hello', (c) => c.json({ hello: 'world', site: c.env.context.site.id }))
|
|
21
|
-
|
|
22
|
-
export default handle(app)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Run it locally with `netlify dev` and publish with `netlify deploy`. The client's address comes from `getConnInfo` of `acrylblends/netlify` (the Netlify context's `ip`); see the [ConnInfo helper](../helpers/conninfo.md).
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Service Worker
|
|
2
|
-
|
|
3
|
-
An Acryl app can answer `fetch` events in a Service Worker, and in any environment that uses the Service Worker syntax, such as a Cloudflare Worker written without ES modules. `fire(app)` from `acrylblends/service-worker` registers the app on the `fetch` event, and `handle(app)` returns the listener, if you want to register it yourself.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a fetch event. It has not been run inside a browser's Service Worker by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Acryl } from 'acrylblends'
|
|
9
|
-
import { fire } from 'acrylblends/service-worker'
|
|
10
|
-
|
|
11
|
-
const app = new Acryl()
|
|
12
|
-
|
|
13
|
-
app.get('/', (c) => c.text('Hello from a Service Worker'))
|
|
14
|
-
|
|
15
|
-
fire(app)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
A request the app does not answer (`404`) can be passed on to the network by giving `fetch` as an option, so a Service Worker can serve some routes and leave the others to the origin:
|
|
19
|
-
|
|
20
|
-
```ts lib=webworker
|
|
21
|
-
import { Acryl } from 'acrylblends'
|
|
22
|
-
import { handle } from 'acrylblends/service-worker'
|
|
23
|
-
|
|
24
|
-
declare const self: ServiceWorkerGlobalScope
|
|
25
|
-
|
|
26
|
-
const app = new Acryl()
|
|
27
|
-
|
|
28
|
-
app.get('/offline', (c) => c.text('Served by the Service Worker'))
|
|
29
|
-
|
|
30
|
-
self.addEventListener('fetch', handle(app, { fetch: globalThis.fetch }))
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
The example is type-checked with the TypeScript `WebWorker` library: declare `self` as a `ServiceWorkerGlobalScope` as above. `app.fire()` (a method of the app) is deprecated in favour of `fire()` from this module.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Vercel
|
|
2
|
-
|
|
3
|
-
Vercel runs a function that takes a `Request` and returns a `Response`, which is what `app.fetch` is. `handle(app)` from `acrylblends/vercel` is that function.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a `Request`. It has not been deployed to Vercel by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
## A function
|
|
8
|
-
|
|
9
|
-
Create `api/index.ts`:
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { Acryl } from 'acrylblends'
|
|
13
|
-
import { handle } from 'acrylblends/vercel'
|
|
14
|
-
|
|
15
|
-
const app = new Acryl().basePath('/api')
|
|
16
|
-
|
|
17
|
-
app.get('/', (c) => c.text('Hello from Vercel'))
|
|
18
|
-
app.get('/hello', (c) => c.json({ hello: 'world' }))
|
|
19
|
-
|
|
20
|
-
export const GET = handle(app)
|
|
21
|
-
export const POST = handle(app)
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Export one handler per HTTP method the app answers. Run it locally with `vercel dev`, and publish with `vercel deploy`.
|
|
25
|
-
|
|
26
|
-
## The client's address
|
|
27
|
-
|
|
28
|
-
The client's address comes from `getConnInfo` of `acrylblends/vercel`, which reads the `x-real-ip` header Vercel sets; see the [ConnInfo helper](../helpers/conninfo.md).
|