Skip to content

Commit a87938a

Browse files
authored
export configuration types
1 parent 9948917 commit a87938a

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ app.prepare().then(() => {
6868
logging: {
6969
// (Optional) The logger to use (defaults to console)
7070
logger: console,
71-
// The log level, must be one of
72-
// 'debug', 'warn' or 'error'
71+
// (Optional) The log level, must be one of
72+
// 'debug', 'warn' or 'error' (defaults to 'error')
7373
level: 'debug'
7474
}
7575
},
@@ -103,11 +103,7 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => {
103103
}
104104

105105
handle(new URL('http://localhost:4000/'), req.query, res, {
106-
signature: {
107-
key: '91bdcda48ce22cd7d8d3a0eda930b3db1762bc1cba5dc13542e723b68fe55d6f9d18199cbe35191a45faf22593405cad0fe76ffec67d24f8aee861ac8fe44d96',
108-
salt: '72456c286761260f320391fe500fcec53755958dabd288867a6db072e1bc1dbd84b15079838a83a715edc1ecad50c3ce91dd8fdef6f981816fa274f91d8ecf06',
109-
},
110-
bucketWhitelist: ['test-bucket'],
106+
// Handler Options
111107
});
112108
};
113109

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitpatty/next-image-s3-imgproxy-loader",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "imgproxy S3 extension for next/image",
55
"author": "Matteias Collet <[email protected]>",
66
"main": "dist/index.js",

src/index.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,69 @@ import pb from '@bitpatty/imgproxy-url-builder';
1313

1414
import Logger, { LoggerOptions } from './logger';
1515

16+
/**
17+
* The options for the request handler
18+
*/
1619
type HandlerOptions = {
20+
/**
21+
* The secrets for signing the URLs
22+
*/
1723
signature?: {
24+
/**
25+
* The hex-encoded imgproxy key (IMGPROXY_KEY)
26+
*/
1827
key: string;
28+
29+
/**
30+
* The hex-encoded imgproxy salt (IMGPROXY_SALT)
31+
*/
1932
salt: string;
2033
};
34+
35+
/**
36+
* The auth token (IMGPROXY_SECRET), will be included in the Authorization request
37+
* header as bearer token
38+
*/
2139
authToken?: string;
40+
41+
/**
42+
* Restrict access to the specified buckets
43+
*/
2244
bucketWhitelist?: string[];
45+
46+
/**
47+
* The imgproxy headers that should be forwarded to the client. Overrides the default
48+
* set of response headers.
49+
*
50+
* If specified, all headers not included in this configuration will be stripped
51+
* from the response.
52+
*/
2353
forwardedHeaders?: string[];
54+
55+
/**
56+
* Additional request headers that should be sent to imgproxy
57+
*/
2458
requestHeaders?: OutgoingHttpHeaders;
59+
60+
/**
61+
* The logger configuration
62+
*/
2563
logging?: LoggerOptions;
2664
};
2765

66+
/**
67+
* The default NextJS endpoint that should be used for proxying the images
68+
*/
2869
const IMGPROXY_ENDPOINT = '/_next/imgproxy';
70+
71+
/**
72+
* The regex for validating whether a source string is valid (<bucket name>/<file name>)
73+
*/
2974
const SRC_REGEX = /^[^/.]+\/.+[^/]$/;
75+
76+
/**
77+
* The default imgproxy response headers that should be forwarded to the client.
78+
*/
3079
const FORWARDED_HEADERS = [
3180
'date',
3281
'expires',
@@ -175,9 +224,23 @@ const handle = (
175224
req.end();
176225
};
177226

227+
/**
228+
* The props for the <ProxyImage /> component
229+
*/
178230
type ProxyImageProps = {
231+
/**
232+
* The file path in the format `<bucket name>/<file-name>`
233+
*/
179234
file: string;
235+
236+
/**
237+
* The imgproxy params
238+
*/
180239
proxyParams?: string;
240+
241+
/**
242+
* The NextJS endpoint handling the proxy request
243+
*/
181244
endpoint?: string;
182245
};
183246

@@ -226,3 +289,4 @@ const ProxyImage = ({
226289

227290
export default ProxyImage;
228291
export { IMGPROXY_ENDPOINT, buildProxyImagePath, handle };
292+
export type { HandlerOptions, ProxyImageProps, LoggerOptions };

0 commit comments

Comments
 (0)