Skip to content

Commit ed16d3e

Browse files
authored
refactor: custom overrides (#77)
1 parent b4b3113 commit ed16d3e

File tree

1 file changed

+145
-8
lines changed

1 file changed

+145
-8
lines changed

pages/aws/config/custom_overrides.mdx

Lines changed: 145 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ to your `open-next.config.ts` to avoid the edge runtime to try to compile overri
1313

1414
## Custom converter
1515

16-
Sometimes you might want to modify the object received by OpenNext. For example `Config.YOUR_SECRET_KEY` from sst cannot be used in the middleware, so you might want to add it to the headers. This is where the custom converter comes in. You can add a custom converter to modify the object before it is passed to OpenNext.
16+
Sometimes you might want to modify the object received by OpenNext. For example `Config.YOUR_SECRET_KEY` from SST cannot be used in the middleware, so you might want to add it to the headers. This is where the custom converter comes in. You can add a custom converter to modify the object before it is passed to OpenNext.
1717

1818
You'll still have to use a fallback value during dev as this is not used by the dev server.
1919

@@ -276,19 +276,156 @@ const config = {
276276
```
277277

278278
## Custom Incremental cache
279-
TODO
280279

281-
## Custom queue
282-
TODO
280+
You can take inspiration from our [`fs-dev`](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/incrementalCache/fs-dev.ts) override which uses the file system to store the incremental cache. You need an `open-next.config.ts` with this:
281+
282+
```ts
283+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.ts';
284+
const config = {
285+
default: {
286+
override: {
287+
// can be any of our included ones or your own custom override
288+
incrementalCache: () => import('./customIncrementalCache').then((mod) => mod.default),
289+
},
290+
},
291+
} satisfies OpenNextConfig;
292+
293+
export default config;
294+
```
295+
296+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/incrementalCache) ones are `'s3' | 's3-lite' | 'multi-tier-ddb-s3' | 'fs-dev' | 'dummy'`
297+
298+
## Custom Queue
299+
300+
By default it will use SQS queue to revalidate stale routes. You can read more about this [here](/aws/config/overrides/queue). To create your own custom override you can take inspiration by looking at our [included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/queue) implementations. You need an `open-next.config.ts` with this:
301+
302+
```ts
303+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.ts';
304+
const config = {
305+
default: {
306+
override: {
307+
// can be any of our included ones or your own custom override
308+
queue: () => import('./customQueue').then((mod) => mod.default),
309+
},
310+
},
311+
} satisfies OpenNextConfig;
312+
313+
export default config;
314+
```
315+
316+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/queue) ones are `'sqs' | 'sqs-lite' | 'direct' | 'dummy'`
283317

284318
## Custom Tag cache
285-
TODO
319+
320+
To override the tag cache you can take inspiration by looking at the [`fs-dev`](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/tagCache/fs-dev.ts) override that uses the filesystem. You can read more about this override [here](/aws/config/overrides/tag_cache). You need an `open-next.config.ts` with this:
321+
322+
```ts
323+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.ts';
324+
const config = {
325+
default: {
326+
override: {
327+
// can be any of our included ones or your own custom override
328+
tagCache: () => import('./customTagCache').then((mod) => mod.default),
329+
},
330+
},
331+
} satisfies OpenNextConfig;
332+
333+
export default config;
334+
```
335+
336+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/tagCache) ones are `'dynamodb' | 'dynamodb-lite' | 'fs-dev' | 'dummy'`
286337

287338
## Custom Origin Resolver
288-
TODO
339+
340+
This override is only used internally by OpenNext to resolve the origin of the request if you have an `external` middleware. You can take inspiration from looking at our included [`pattern-env`](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/originResolver/pattern-env.ts) override. You need an `open-next.config.ts` with this:
341+
342+
```ts
343+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js';
344+
const config = {
345+
default: {},
346+
middleware: {
347+
// must be true for the originResolver to be used
348+
external: true,
349+
// can be any of our included ones or your own custom override
350+
originResolver: () => import('./customOriginResolver').then((mod) => mod.default),
351+
},
352+
} satisfies OpenNextConfig;
353+
354+
export default config;
355+
```
356+
357+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/originResolver) ones are `'pattern-env' | 'dummy'`
289358

290359
## Custom Image Loader
291-
TODO
360+
361+
This override is used in the image optimization server to load an image from a custom source. You can look at our implemention of using the file system [here](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/imageLoader/fs-dev.ts). You need an `open-next.config.ts` with this:
362+
363+
```ts
364+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js';
365+
const config = {
366+
default: {},
367+
imageOptimization: {
368+
loader: () => import('./customImageLoader').then((mod) => mod.default),
369+
},
370+
} satisfies OpenNextConfig;
371+
372+
export default config;
373+
```
374+
375+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/imageLoader) ones are `'s3' | 's3-lite' | 'host' | 'fs-dev' | 'dummy'`
292376

293377
## Custom Warmer Invoke
294-
TODO
378+
379+
To have a custom override for the warmer invoke you can take inspiration by looking at our [`aws-lambda`](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/warmer/aws-lambda.ts) override. You need an `open-next.config.ts` with this:
380+
381+
```ts
382+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js';
383+
const config = {
384+
default: {},
385+
warmer: {
386+
invokeFunction: () => import('./customWarmer').then((mod) => mod.default),
387+
},
388+
} satisfies OpenNextConfig;
389+
390+
export default config;
391+
```
392+
393+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/warmer) ones are `'aws-lambda' | 'dummy'`
394+
395+
## Custom CDN Invalidation
396+
397+
To have a custom override for the CDN Invalidation you can take inspiration by looking at our [`cloudfront`](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/cdnInvalidation/cloudfront.ts) override. You need an `open-next.config.ts` with this:
398+
399+
```ts
400+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js';
401+
const config = {
402+
default: {
403+
override: {
404+
cdnInvalidation: () => import('./customCdnInvalidation').then((mod) => mod.default),
405+
}
406+
},
407+
} satisfies OpenNextConfig;
408+
409+
export default config;
410+
```
411+
412+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/cdnInvalidation) ones are `'cloudfront' | 'dummy'`
413+
414+
## Custom External Request Proxy
415+
416+
This is used by OpenNext to proxy rewritten requests to external services. You can read more about it [here](/aws/config/overrides/proxy_external_request). To have a custom override for the External Request Proxy you can take inspiration by looking at our [`fetch`](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/proxyExternalRequest/fetch.ts) override. You need an `open-next.config.ts` with this:
417+
418+
```ts
419+
import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js';
420+
const config = {
421+
default: {
422+
override: {
423+
proxyExternalRequest: () => import('./customProxyExternalRequest').then((mod) => mod.default),
424+
}
425+
},
426+
} satisfies OpenNextConfig;
427+
428+
export default config;
429+
```
430+
431+
[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/proxyExternalRequest) ones are `'fetch' | 'node' | 'dummy'`

0 commit comments

Comments
 (0)