Skip to content

Commit 6370041

Browse files
Fix too-low default qs limits and enforce them with proper error handling
The qs library update lowered default arrayLimit/parameterLimit, causing valid requests to silently lose options. Limits are now derived from the loaded schemas so they always match the actual styles. Enables throwOnLimitExceeded to return a 400 response instead of silently truncating — the querystringParser error is caught and surfaced via an onRequest hook in Fastify's standard error format. Fixes #16
1 parent 7c25771 commit 6370041

15 files changed

Lines changed: 1599 additions & 822 deletions

README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,82 @@
11
<h1><img src="https://dicebear.com/logo-readme.svg" width="28" /> DiceBear API</h1>
22

3-
This is the source code for the [DiceBear API](https://dicebear.com/how-to-use/http-api). It's built on [Fastify](https://fastify.io/).
4-
Learn how to set up your own instance of the API in the [documentation](https://dicebear.com/guides/host-the-http-api-yourself).
3+
Self-host the DiceBear avatar API for privacy-by-design and commercial use. Built on [Fastify](https://fastify.io/).
54

65
[Playground](https://dicebear.com/playground/) |
7-
[Documentation](https://dicebear.com/guides/host-the-http-api-yourself/)
6+
[Documentation](https://dicebear.com/guides/host-the-http-api-yourself/) |
7+
[Docker Hub](https://hub.docker.com/r/dicebear/api)
8+
9+
## Getting Started
10+
11+
### With Docker
12+
13+
```sh
14+
docker run --tmpfs /run --tmpfs /tmp -p 3000:3000 -i -t dicebear/api:3
15+
```
16+
17+
Or with `docker-compose.yml`:
18+
19+
```yaml
20+
services:
21+
dicebear:
22+
image: dicebear/api:3
23+
restart: always
24+
ports:
25+
- '3000:3000'
26+
tmpfs:
27+
- '/run'
28+
- '/tmp'
29+
```
30+
31+
### Without Docker
32+
33+
Requires [Node.js](https://nodejs.org/).
34+
35+
```sh
36+
git clone git@github.com:dicebear/api.git
37+
cd api
38+
39+
npm install
40+
npm run build
41+
npm start
42+
```
43+
44+
## Environment Variables
45+
46+
| Variable | Default | Description |
47+
| ---------------------------------- | ----------- | ---------------------------------------------------------- |
48+
| `PORT` | `3000` | Port to listen on. |
49+
| `HOST` | `0.0.0.0` | Host to bind to (all IPv4 addresses by default). |
50+
| `LOGGER` | `0` | Enable request logger (1 = on, 0 = off). |
51+
| `WORKERS` | `1` | Number of Node.js worker threads. |
52+
| `VERSIONS` | `5,6,7,8,9` | Comma-separated list of supported DiceBear major versions. |
53+
| `CACHE_CONTROL_AVATARS` | `31536000` | Cache duration for avatar responses in seconds (1 year). |
54+
| `PNG` | `1` | Enable the PNG endpoint (1 = on, 0 = off). |
55+
| `PNG_SIZE_MIN` | `1` | Minimum allowed PNG size in px. |
56+
| `PNG_SIZE_MAX` | `256` | Maximum allowed PNG size in px. |
57+
| `PNG_SIZE_DEFAULT` | `128` | Default PNG size in px. |
58+
| `PNG_EXIF` | `1` | Enable EXIF metadata for PNG (1 = on, 0 = off). |
59+
| `JPEG` | `1` | Enable the JPEG endpoint (1 = on, 0 = off). |
60+
| `JPEG_SIZE_MIN` | `1` | Minimum allowed JPEG size in px. |
61+
| `JPEG_SIZE_MAX` | `256` | Maximum allowed JPEG size in px. |
62+
| `JPEG_SIZE_DEFAULT` | `128` | Default JPEG size in px. |
63+
| `JPEG_EXIF` | `1` | Enable EXIF metadata for JPEG (1 = on, 0 = off). |
64+
| `WEBP` | `1` | Enable the WebP endpoint (1 = on, 0 = off). |
65+
| `WEBP_SIZE_MIN` | `1` | Minimum allowed WebP size in px. |
66+
| `WEBP_SIZE_MAX` | `256` | Maximum allowed WebP size in px. |
67+
| `WEBP_SIZE_DEFAULT` | `128` | Default WebP size in px. |
68+
| `WEBP_EXIF` | `1` | Enable EXIF metadata for WebP (1 = on, 0 = off). |
69+
| `AVIF` | `1` | Enable the AVIF endpoint (1 = on, 0 = off). |
70+
| `AVIF_SIZE_MIN` | `1` | Minimum allowed AVIF size in px. |
71+
| `AVIF_SIZE_MAX` | `256` | Maximum allowed AVIF size in px. |
72+
| `AVIF_SIZE_DEFAULT` | `128` | Default AVIF size in px. |
73+
| `AVIF_EXIF` | `1` | Enable EXIF metadata for AVIF (1 = on, 0 = off). |
74+
| `JSON` | `1` | Enable the JSON endpoint (1 = on, 0 = off). |
75+
| `QUERY_STRING_ARRAY_LIMIT_MIN` | `20` | Minimum number of values allowed per array parameter. |
76+
| `QUERY_STRING_PARAMETER_LIMIT_MIN` | `100` | Minimum number of query string parameters allowed. |
77+
78+
> [!NOTE]
79+
> The `*_EXIF` variables require [Perl](https://www.npmjs.com/package/exiftool-vendored#installation) and [procps](https://www.npmjs.com/package/exiftool-vendored#this-package-requires-procps) to be installed.
880
981
## Sponsors
1082

eslint.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tseslint from 'typescript-eslint';
2+
3+
export default tseslint.config(...tseslint.configs.recommended, {
4+
rules: {
5+
'padding-line-between-statements': [
6+
'error',
7+
{ blankLine: 'always', prev: '*', next: 'block-like' },
8+
{ blankLine: 'always', prev: 'block-like', next: '*' },
9+
],
10+
},
11+
});

0 commit comments

Comments
 (0)