Skip to content

Commit 75c3b3c

Browse files
sommeeeerconico974
andauthored
refactor: overrides (#79)
Co-authored-by: conico974 <[email protected]>
1 parent 6d4b9c5 commit 75c3b3c

File tree

7 files changed

+66
-9
lines changed

7 files changed

+66
-9
lines changed

pages/aws/config/overrides/automatic_cdn_invalidation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Callout} from 'nextra/components'
22

33
Available since `@opennextjs/aws` 3.4.0
44

5-
This override is used by OpenNext when routes have been On-Demand revalidated and the CDN needs to be updated. It is not called for ISR revalidation.
5+
Not enabled by default. This override is used by OpenNext when routes have been On-Demand revalidated and the CDN needs to be updated. It is not called for ISR revalidation.
66
It will be called for `revalidatePath`, `revalidateTag` and `res.revalidate()`.
77

88
If you want to better understand how to implement your own Automatic CDN Invalidation, the easiest way would be to take a look at the existing [included Automatic CDN Invalidation](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/cdnInvalidation)

pages/aws/config/overrides/converter.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,34 @@ Couple of things to note :
66
- If you use a `StreamCreator` in your wrapper, you probably don't need to do anything in the `convertTo` function.
77
- If used for the default, the image optimization, or one of the splitted server the internal types will be `InternalEvent` and `InternalResult` respectively.
88
- If used for the external middleware, the internal types will be `InternalEvent` and `InternalResult | MiddlewareResult` respectively.
9-
- For the other servers, look up their respective types in the codebase.
9+
- For the other servers, look up their respective types in the codebase.
10+
11+
## Included Converters
12+
13+
### aws-apigw-v2
14+
15+
The `aws-apigw-v2` Converter is the default convert for AWS. It is used by default if you don't provide any Converter in your configuration.
16+
17+
### aws-apigw-v1
18+
19+
The `aws-apigw-v1` Converter is a converter that allows you to convert request and response from Amazon API Gateway v1.
20+
21+
### aws-cloudfront
22+
23+
The `aws-cloudfront` Converter is a converter for Cloudfront (i.e. lambda@edge)
24+
25+
### edge
26+
27+
The `edge` Converter is the converter for everything that uses `Request` and `Response`. At the moment with the builtin one that's only Cloudflare.
28+
29+
### converter
30+
31+
The `node` Converter is a converter for classic Node.js server.
32+
33+
### sqs-revalidate
34+
35+
The `sqs-revalidate` Converter is a converter for the Revalidation server. It uses SQS Queue to handle the revalidation.
36+
37+
### dummy
38+
39+
The `dummy` Converter is a dummy implementation that will just forward the request and response as is.

pages/aws/config/overrides/image_loader.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ It uses the `@aws-sdk/client-s3` to interact with S3.
1515

1616
- You need to provide the `BUCKET_KEY_PREFIX`, `BUCKET_NAME` environment variables to your server.
1717

18+
### s3-lite
19+
20+
The `s3-lite` ImageLoader will load images from an S3 bucket. It uses the `aws4fetch` to interact with S3.
21+
22+
##### Requirements
23+
24+
- You need to provide the `BUCKET_KEY_PREFIX`, `BUCKET_NAME` environment variables to your server.
25+
- Can also provide `BUCKET_REGION`. It fallbacks to `AWS_REGION` ?? `AWS_DEFAULT_REGION`. This should be set by AWS automatically. You can read more about how this works on AWS Lambdas [here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime).
26+
1827
### host
1928

2029
The Host ImageLoader will load images from the host.
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
This override is used by OpenNext to proxy rewritten requests to external services. It is used either in the `external` middleware (if set) or in the default/splitted server if the middleware is bundled.
22

3-
If you want to better understand how to implement your own ProxyExternalRequest, the easiest way would be to take a look at the existing [included ProxyExternalRequest](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/proxyExternalRequest).
3+
If you want to better understand how to implement your own ProxyExternalRequest, the easiest way would be to take a look at the existing [included ProxyExternalRequest](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/proxyExternalRequest).
4+
5+
## Included Proxy External Request
6+
7+
### node
8+
9+
This uses node-proxy to proxy the request to the external service.
10+
11+
### fetch
12+
13+
This uses fetch to proxy the request to the external service. It doesn't work in Node.js
14+
15+
### dummy
16+
17+
This is a dummy implementation that throws a FatalError.

pages/aws/config/overrides/queue.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you want to better understand how to implement your own Queue, the easiest wa
77

88
Couple of things to note :
99
- The default implementation use an SQS queue. This has the main advantage of being able to control the concurrency of the revalidations as well as avoiding trigerring the revalidation multiple times for the same route.
10-
- You don't have to use a queue at all. You could trigger the revalidation directly in the Queue override itself. You can see a very simple implementation of this [in the `queue` override](/aws/contribute/local_run#devqueuets).
10+
- You don't have to use a queue at all. You could trigger the revalidation directly in the Queue override itself. You can see a very simple implementation of this [in the `direct` override](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/queue/direct.ts).
1111

1212
## Included Queue
1313

@@ -18,7 +18,7 @@ It uses the `@aws-sdk/client-sqs` to interact with SQS.
1818

1919
#### Requirements
2020

21-
- You need to provide the `QUEUE_URL` environment variable to your server.
21+
- You need to provide the `REVALIDATION_QUEUE_URL` environment variable to your server.
2222

2323
### sqs-lite
2424

@@ -27,7 +27,7 @@ This implementation is a lighter version of the `sqs` Queue as it uses `aws4fetc
2727

2828
#### Requirements
2929

30-
- You need to provide the `QUEUE_URL`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` environment variables to your server.
30+
- You need to provide the `REVALIDATION_QUEUE_URL`, `REVALIDATION_QUEUE_REGION`(will fallback to `us-east-1`), `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` environment variables to your server.
3131

3232
### direct
3333

pages/aws/config/overrides/tag_cache.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
This override is used by the [`cache` adapter](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/cache.ts) that is provided by OpenNext to the NextServer. It is also used by OpenNext if `enableCacheInterception` is set to `true` in the configuration and by the `initializationFunction` for prepopulating the cache.
22

33
It is used for the cache tags (i.e. `revalidateTag` and `revalidatePath`). It does not handle anything related to the ISR/SSG cache or the fetch cache used by Next.js.
4-
It's main role is to detremine if a path is stale based on the tags and also to update the tag cache when `revalidateTag` is called.
4+
It's main role is to determine if a path is stale based on the tags and also to update the tag cache when `revalidateTag` is called.
55

66
The current implementation differs from the way Next.js standalone handle cache tags. In the standalone version, the cache tags are stored in a file, and every time a cache entry is accessed, it has to check for every tags if the entry is stale. This approach is very read heavy and doesn't work well with DB like DynamoDB.
77
We choose to go another way. We store tags for every path that exists in the cache. This way, we can easily know if a path is stale by just checking the path instead of every tags used. This approach is more write heavy but it's a tradeoff we are willing to make.
@@ -33,10 +33,14 @@ This implementation is a lighter version of the `dynamodb` TagCache as it uses `
3333
- You need to provide the `CACHE_DYNAMO_TABLE`, `CACHE_BUCKET_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` environment variables to your server.
3434
- DynamoDB table should have a primary key `path` of type `String` and a sort key `tag` of type `String`. (It can reuse the same table as the one used by the default `tagCache`)
3535

36+
### dynamodb-nextMode
37+
38+
TBA
39+
3640
### dummy
3741

3842
The Dummy TagCache is a dummy implementation that will throw an exception. It should not be used unless you want to disable cache tags.
3943

4044
### fs-dev
4145

42-
The FsDev TagCache is a simple implementation that stores the cache tags in a file in the `.open-next/cache` folder and interact with it using the filesystem. It is useful for development purposes only.
46+
The FsDev TagCache is a simple implementation that stores the cache tags in a file in the `.open-next/cache` folder and interact with it using the filesystem. It is useful for development purposes only.

pages/aws/config/overrides/wrapper.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Couple of things to note :
66
- If you want to use streaming (for the `node` runtime of next), you'll need to create a `StreamCreator` and pass it to the `handler`. You can find some example in the [node](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/wrappers/node.ts) or [aws-lambda-streaming](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/wrappers/aws-lambda-streaming.ts) wrapper.
77
- If you don't use streaming (like in the default `aws-lambda` wrapper), you may still need to provide a fake `StreamCreator` to the `handler` to avoid a weird issue with Node itself (see [here](https://github.com/opennextjs/opennextjs-aws/blob/f685ddea8f8a5c82591dc02713aff7138f2d9896/packages/open-next/src/overrides/wrappers/aws-lambda.ts#L49-L65) for an example and a more thorough explanation).
88
- If you use the `edge` runtime of Next (either for the external middleware or for an `edge` route or page), you don't need the `StreamCreator` at all.
9-
- If you are in a serverless environment and it supports `waitUntil`, you should define it here(see [here](https://github.com/opennextjs/opennextjs-aws/blob/f685ddea8f8a5c82591dc02713aff7138f2d9896/packages/open-next/src/overrides/wrappers/cloudflare.ts#L29)). This might not be necessary depending on where you run it (for example the `aws-lambda-streaming` or the `node` wrapper doesn't need it.)
9+
- If you are in a serverless environment and it supports `waitUntil`, you should define it here(see [here](https://github.com/opennextjs/opennextjs-aws/blob/b0b1f7776b41612d2638a33e3c9ced8c42afab0a/packages/open-next/src/overrides/wrappers/cloudflare-node.ts#L80). This might not be necessary depending on where you run it (for example the `aws-lambda-streaming` or the `node` wrapper doesn't need it.)
1010

1111

1212
## Included Wrappers

0 commit comments

Comments
 (0)