You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library proxies request through a next endpoint. To register the endpoint create a [custom server](https://nextjs.org/docs/advanced-features/custom-server) in your project and add the following lines:
23
+
#### Method 1: Custom Server
24
+
25
+
The library by default proxies request through a custom endpoint. To register the endpoint create a [custom server](https://nextjs.org/docs/advanced-features/custom-server) in your project and add the following lines:
24
26
25
27
```js
26
28
// server.js
@@ -69,6 +71,38 @@ app.prepare().then(() => {
69
71
});
70
72
```
71
73
74
+
#### Method 2: API Endpoint
75
+
76
+
For serverless environments you can use an API endpoint instead of a custom endpoint.
77
+
78
+
The setup is similar, register your endpoint as follows:
With this method, you have to [supply the endpoint](#overriding-the-endpoint) to the `<ProxyImage>` component.
105
+
72
106
## Using the component
73
107
74
108
After registering the endpoint you can use the `<ProxyImage />` component as you would with the `Image` component from `next/image`, except that you need to provide a file (`<bucketname>/<filename>`) instead of `src` and optional proxy params for image transformations/optimizations.
You can override the default endpoint address or use an absolute address in the component instead.
126
-
127
-
```js
128
-
// server.js
129
-
createServer((req, res) => {
130
-
// ...
131
-
if (pathname ==='/my-endpoint') {
132
-
// ...
133
-
}
134
-
}
135
-
```
159
+
If you use a different endpoint than the one provided by `IMGPROXY_ENDPOINT` you can override the endpoint used by the component by providing the `endpoint` property. `endpoint` can be both a path but also a URL.
0 commit comments