@@ -13,20 +13,69 @@ import pb from '@bitpatty/imgproxy-url-builder';
1313
1414import Logger , { LoggerOptions } from './logger' ;
1515
16+ /**
17+ * The options for the request handler
18+ */
1619type 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+ */
2869const IMGPROXY_ENDPOINT = '/_next/imgproxy' ;
70+
71+ /**
72+ * The regex for validating whether a source string is valid (<bucket name>/<file name>)
73+ */
2974const SRC_REGEX = / ^ [ ^ / . ] + \/ .+ [ ^ / ] $ / ;
75+
76+ /**
77+ * The default imgproxy response headers that should be forwarded to the client.
78+ */
3079const 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+ */
178230type 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
227290export default ProxyImage ;
228291export { IMGPROXY_ENDPOINT , buildProxyImagePath , handle } ;
292+ export type { HandlerOptions , ProxyImageProps , LoggerOptions } ;
0 commit comments