Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pages/aws/config/custom_overrides.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,21 @@ export default config;
```

[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/proxyExternalRequest) ones are `'fetch' | 'node' | 'dummy'`

## Custom Asset Resolver

This is used by OpenNext to resolve static assets. You can read more about it [here](/aws/config/overrides/asset_resolver). To have a custom override for the Asset Resolver, you need an `open-next.config.ts` with this:

```ts
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
const config = {
default: {},
middleware: {
assetResolver: import("./customAssetResolver").then((mod) => mod.default),
},
} satisfies OpenNextConfig;

export default config;
```

[Included](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/assetResolver) one is `'dummy'`
3 changes: 2 additions & 1 deletion pages/aws/config/overrides/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"proxy_external_request": "External Request Proxy",
"origin_resolver": "Origin Resolver",
"invoke_function": "Invoke Function for the warmer",
"automatic_cdn_invalidation": "Automatic CDN Invalidation"
"automatic_cdn_invalidation": "Automatic CDN Invalidation",
"asset_resolver": "Asset Resolver"
}
27 changes: 27 additions & 0 deletions pages/aws/config/overrides/asset_resolver.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Available since `@opennextjs/aws` 3.7.0

This override is used by OpenNext to serve [static assets](https://nextjs.org/docs/app/api-reference/file-conventions/public-folder) from the routing layer.

It is not enabled by default as the assumption is that assets are served before reaching the Open Next server.

When assets are not served before the Open Next server, you can create an Asset Resolver to serve them. It will be invoked [after the `beforeFiles` (`rewrites`) from `next.config.ts`](https://nextjs.org/docs/app/api-reference/file-conventions/middleware#execution-order).

## Implementation

An Asset Resolver should implement:

```ts
export interface AssetResolver {
name: string;

maybeGetAssetResult?: (event: InternalEvent) => Promise<InternalResult | undefined> | undefined;
}
```

`maybeGetAssetResult` is invoked with the `InternalEvent` and should return a `Promise<InternalResult>` to serve an asset when the incoming event matches one. When it returns `Promise<undefined>` or `undefined`, the routing process keeps going to try and match Next routes.

## Included Asset Resolver

### dummy

The dummy `AssetResolver` does nothing so it never serves assets. It is the default implementation.