create-tigra 3.3.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/README.md +264 -56
  3. package/bin/create-tigra.js +497 -472
  4. package/lib/patchers/email-verification.patcher.js +72 -10
  5. package/modules/email-verification/client/hooks/useVerification.ts +4 -1
  6. package/modules/email-verification/server/__tests__/verification.integration.test.ts +115 -0
  7. package/modules/email-verification/server/verification.controller.ts +3 -1
  8. package/modules/email-verification/server/verification.service.ts +44 -13
  9. package/package.json +5 -3
  10. package/template/.github/dependabot.yml +47 -0
  11. package/template/.github/workflows/audit.yml +36 -0
  12. package/template/.github/workflows/ci.yml +79 -0
  13. package/template/AGENTS.md +18 -9
  14. package/template/README.md +79 -0
  15. package/template/client/.dockerignore +1 -0
  16. package/template/client/.env.example.production +13 -2
  17. package/template/client/AGENTS.md +13 -5
  18. package/template/client/Dockerfile +186 -14
  19. package/template/client/README.md +92 -21
  20. package/template/client/next.config.ts +1 -1
  21. package/template/client/package-lock.json +15983 -14181
  22. package/template/client/package.json +56 -48
  23. package/template/client/scripts/check-sharp.mjs +53 -0
  24. package/template/client/scripts/next-dev.cjs +5 -1
  25. package/template/client/src/__tests__/proxy.test.ts +92 -0
  26. package/template/client/src/app/healthz/route.ts +16 -0
  27. package/template/client/src/app/layout.tsx +9 -3
  28. package/template/client/src/app/page.tsx +2 -2
  29. package/template/client/src/app/providers.tsx +23 -4
  30. package/template/client/src/components/layout/Header.tsx +7 -3
  31. package/template/client/src/features/admin/hooks/useAdminSessions.ts +2 -1
  32. package/template/client/src/features/admin/hooks/useAdminUsers.ts +3 -1
  33. package/template/client/src/features/admin/types/admin.types.ts +2 -3
  34. package/template/client/src/features/auth/components/AuthInitializer.tsx +35 -18
  35. package/template/client/src/features/auth/components/ForgotPasswordForm.tsx +107 -0
  36. package/template/client/src/features/auth/components/LimitNotice.tsx +28 -0
  37. package/template/client/src/features/auth/components/LoginForm.tsx +13 -2
  38. package/template/client/src/features/auth/components/RegisterForm.tsx +23 -7
  39. package/template/client/src/features/auth/hooks/useAuth.ts +11 -1
  40. package/template/client/src/features/auth/hooks/usePasswordReset.ts +7 -1
  41. package/template/client/src/features/auth/services/auth.service.ts +8 -3
  42. package/template/client/src/features/auth/store/authSlice.ts +7 -2
  43. package/template/client/src/lib/api/__tests__/axios.config.test.ts +183 -0
  44. package/template/client/src/lib/api/api.types.ts +14 -0
  45. package/template/client/src/lib/api/axios.config.ts +101 -15
  46. package/template/client/src/lib/api/hard-redirect.ts +8 -0
  47. package/template/client/src/lib/api/session-events.ts +29 -0
  48. package/template/client/src/lib/constants/routes.ts +12 -0
  49. package/template/client/src/lib/observability/sentry-scrub.ts +1 -1
  50. package/template/client/src/lib/utils/__tests__/error.test.ts +119 -0
  51. package/template/client/src/lib/utils/__tests__/form.test.ts +42 -0
  52. package/template/client/src/lib/utils/__tests__/paths.test.ts +43 -0
  53. package/template/client/src/lib/utils/__tests__/security.test.ts +40 -0
  54. package/template/client/src/lib/utils/__tests__/session-marker.test.ts +27 -0
  55. package/template/client/src/lib/utils/error.ts +81 -0
  56. package/template/client/src/lib/utils/form.ts +31 -0
  57. package/template/client/src/lib/utils/paths.ts +18 -0
  58. package/template/client/src/lib/utils/session-marker.ts +24 -0
  59. package/template/client/src/{middleware.ts → proxy.ts} +25 -11
  60. package/template/client/src/store/__tests__/store.test.ts +44 -0
  61. package/template/client/src/store/index.ts +26 -8
  62. package/template/client/vitest.config.mts +48 -0
  63. package/template/server/.env.example +280 -270
  64. package/template/server/.env.example.production +283 -242
  65. package/template/server/AGENTS.md +13 -4
  66. package/template/server/Dockerfile +176 -14
  67. package/template/server/README.md +108 -0
  68. package/template/server/docker-compose.yml +4 -2
  69. package/template/server/docs/deployment.md +63 -0
  70. package/template/server/docs/logging.md +66 -4
  71. package/template/server/docs/rate-limits.md +153 -0
  72. package/template/server/docs/testing.md +81 -0
  73. package/template/server/eslint.config.mjs +19 -0
  74. package/template/server/package-lock.json +8784 -8743
  75. package/template/server/package.json +79 -75
  76. package/template/server/prisma/migrations/0_init/migration.sql +82 -0
  77. package/template/server/prisma/migrations/migration_lock.toml +3 -0
  78. package/template/server/prisma/schema.prisma +0 -3
  79. package/template/server/scripts/check-heic.mjs +40 -0
  80. package/template/server/scripts/check-sharp.mjs +53 -0
  81. package/template/server/src/__tests__/routes.integration.test.ts +280 -0
  82. package/template/server/src/app.ts +248 -346
  83. package/template/server/src/config/__tests__/env.test.ts +219 -0
  84. package/template/server/src/config/__tests__/rate-limit.config.test.ts +158 -0
  85. package/template/server/src/config/env.ts +326 -182
  86. package/template/server/src/config/rate-limit.config.ts +157 -106
  87. package/template/server/src/jobs/__tests__/cleanup-deleted-accounts.job.test.ts +60 -8
  88. package/template/server/src/jobs/__tests__/cleanup-expired-auth.job.test.ts +44 -0
  89. package/template/server/src/jobs/__tests__/jobs.integration.test.ts +88 -0
  90. package/template/server/src/jobs/__tests__/schedule.test.ts +92 -0
  91. package/template/server/src/jobs/cleanup-deleted-accounts.job.ts +38 -36
  92. package/template/server/src/jobs/cleanup-expired-auth.job.ts +32 -24
  93. package/template/server/src/jobs/index.ts +12 -2
  94. package/template/server/src/jobs/refresh-cloudflare-ranges.job.ts +28 -0
  95. package/template/server/src/jobs/schedule.ts +50 -0
  96. package/template/server/src/libs/__tests__/auth.test.ts +98 -7
  97. package/template/server/src/libs/__tests__/client-ip.test.ts +257 -121
  98. package/template/server/src/libs/__tests__/cloudflare-ranges.test.ts +79 -0
  99. package/template/server/src/libs/__tests__/cookies.test.ts +53 -2
  100. package/template/server/src/libs/__tests__/email-quota.test.ts +81 -0
  101. package/template/server/src/libs/__tests__/email.test.ts +68 -0
  102. package/template/server/src/libs/__tests__/error-handler.test.ts +162 -0
  103. package/template/server/src/libs/__tests__/health-db-down.integration.test.ts +37 -0
  104. package/template/server/src/libs/__tests__/health-redis-down.integration.test.ts +45 -0
  105. package/template/server/src/libs/__tests__/health-routes.test.ts +83 -0
  106. package/template/server/src/libs/__tests__/health.integration.test.ts +118 -0
  107. package/template/server/src/libs/__tests__/http.test.ts +74 -2
  108. package/template/server/src/libs/__tests__/ip-block.test.ts +179 -62
  109. package/template/server/src/libs/__tests__/logger.test.ts +50 -0
  110. package/template/server/src/libs/__tests__/monitoring.test.ts +185 -0
  111. package/template/server/src/libs/__tests__/outbound.integration.test.ts +48 -0
  112. package/template/server/src/libs/__tests__/prisma-client.test.ts +28 -0
  113. package/template/server/src/libs/__tests__/query-counter.integration.test.ts +53 -0
  114. package/template/server/src/libs/__tests__/rate-limiting.test.ts +146 -0
  115. package/template/server/src/libs/__tests__/rate-limits.integration.test.ts +53 -0
  116. package/template/server/src/libs/__tests__/redis-required.test.ts +30 -0
  117. package/template/server/src/libs/__tests__/redis.test.ts +38 -2
  118. package/template/server/src/libs/__tests__/request-id.test.ts +25 -0
  119. package/template/server/src/libs/__tests__/requestLogger.test.ts +126 -0
  120. package/template/server/src/libs/__tests__/safe-http.test.ts +138 -0
  121. package/template/server/src/libs/__tests__/sentry-scrub.test.ts +82 -80
  122. package/template/server/src/libs/__tests__/shutdown.test.ts +89 -0
  123. package/template/server/src/libs/__tests__/url-safety.test.ts +130 -80
  124. package/template/server/src/libs/auth.ts +39 -10
  125. package/template/server/src/libs/client-ip.ts +158 -77
  126. package/template/server/src/libs/cloudflare-ranges.ts +132 -0
  127. package/template/server/src/libs/cookies.ts +53 -14
  128. package/template/server/src/libs/email-quota.ts +74 -0
  129. package/template/server/src/libs/email.ts +46 -9
  130. package/template/server/src/libs/error-handler.ts +111 -0
  131. package/template/server/src/libs/health-routes.ts +53 -0
  132. package/template/server/src/libs/http.ts +139 -47
  133. package/template/server/src/libs/ip-address.ts +37 -0
  134. package/template/server/src/libs/ip-block.ts +284 -221
  135. package/template/server/src/libs/logger.ts +41 -12
  136. package/template/server/src/libs/monitoring.ts +127 -41
  137. package/template/server/src/libs/observability/sentry.ts +1 -1
  138. package/template/server/src/libs/origin-check.ts +9 -7
  139. package/template/server/src/libs/prisma.ts +47 -4
  140. package/template/server/src/libs/query-counter.ts +71 -59
  141. package/template/server/src/libs/rate-limiting.ts +110 -0
  142. package/template/server/src/libs/redis-required.ts +28 -0
  143. package/template/server/src/libs/redis.ts +27 -1
  144. package/template/server/src/libs/request-id.ts +18 -0
  145. package/template/server/src/libs/requestLogger.ts +112 -17
  146. package/template/server/src/libs/safe-http.ts +101 -0
  147. package/template/server/src/libs/shutdown.ts +87 -0
  148. package/template/server/src/libs/storage/__tests__/fixtures/tiny-heic.ts +13 -0
  149. package/template/server/src/libs/storage/__tests__/image-optimizer.test.ts +59 -0
  150. package/template/server/src/libs/storage/__tests__/multipart-limits.test.ts +91 -0
  151. package/template/server/src/libs/storage/__tests__/upload-persistence.test.ts +52 -0
  152. package/template/server/src/libs/storage/file-storage.service.ts +94 -84
  153. package/template/server/src/libs/storage/file-validator.ts +48 -46
  154. package/template/server/src/libs/storage/image-optimizer.service.ts +16 -5
  155. package/template/server/src/libs/token-hash.ts +18 -0
  156. package/template/server/src/libs/url-safety.ts +127 -121
  157. package/template/server/src/libs/validation-errors.ts +86 -0
  158. package/template/server/src/modules/admin/__tests__/admin-actions.integration.test.ts +255 -0
  159. package/template/server/src/modules/admin/__tests__/admin.health.test.ts +82 -0
  160. package/template/server/src/modules/admin/__tests__/admin.repo.test.ts +55 -0
  161. package/template/server/src/modules/admin/__tests__/admin.schemas.test.ts +38 -0
  162. package/template/server/src/modules/admin/__tests__/admin.service.test.ts +162 -0
  163. package/template/server/src/modules/admin/admin.controller.ts +66 -49
  164. package/template/server/src/modules/admin/admin.repo.ts +49 -10
  165. package/template/server/src/modules/admin/admin.routes.ts +48 -2
  166. package/template/server/src/modules/admin/admin.schemas.ts +18 -6
  167. package/template/server/src/modules/admin/admin.service.ts +66 -4
  168. package/template/server/src/modules/auth/__tests__/auth.controller.test.ts +39 -0
  169. package/template/server/src/modules/auth/__tests__/auth.integration.test.ts +9 -3
  170. package/template/server/src/modules/auth/__tests__/auth.service.dummy-hash.test.ts +34 -0
  171. package/template/server/src/modules/auth/__tests__/auth.service.test.ts +197 -37
  172. package/template/server/src/modules/auth/__tests__/session-cleanup.test.ts +39 -0
  173. package/template/server/src/modules/auth/__tests__/sessions.integration.test.ts +246 -0
  174. package/template/server/src/modules/auth/__tests__/token-fingerprints.test.ts +119 -0
  175. package/template/server/src/modules/auth/auth.controller.ts +133 -128
  176. package/template/server/src/modules/auth/auth.repo.ts +44 -44
  177. package/template/server/src/modules/auth/auth.schemas.ts +4 -2
  178. package/template/server/src/modules/auth/auth.service.ts +167 -96
  179. package/template/server/src/modules/auth/session.repo.ts +12 -0
  180. package/template/server/src/modules/files/__tests__/files.integration.test.ts +5 -5
  181. package/template/server/src/modules/users/__tests__/avatar-upload.test.ts +120 -0
  182. package/template/server/src/modules/users/__tests__/name-rules.test.ts +46 -0
  183. package/template/server/src/modules/users/__tests__/users.integration.test.ts +295 -0
  184. package/template/server/src/modules/users/__tests__/users.repo.test.ts +37 -0
  185. package/template/server/src/modules/users/__tests__/users.service.test.ts +129 -0
  186. package/template/server/src/modules/users/users.controller.ts +9 -38
  187. package/template/server/src/modules/users/users.repo.ts +23 -7
  188. package/template/server/src/modules/users/users.routes.ts +3 -22
  189. package/template/server/src/modules/users/users.schemas.ts +15 -9
  190. package/template/server/src/modules/users/users.service.ts +105 -93
  191. package/template/server/src/scripts/make-admin.ts +48 -0
  192. package/template/server/src/server.ts +48 -26
  193. package/template/server/src/shared/errors/AppError.ts +27 -1
  194. package/template/server/src/shared/errors/errors.ts +42 -5
  195. package/template/server/src/shared/responses/successResponse.ts +22 -3
  196. package/template/server/src/shared/types/index.ts +7 -0
  197. package/template/server/src/test/__tests__/integration-services.test.ts +66 -0
  198. package/template/server/src/test/integration-helpers.ts +343 -0
  199. package/template/server/src/test/integration-services.ts +74 -0
  200. package/template/server/src/test/integration.global-setup.ts +144 -0
  201. package/template/server/src/test/integration.setup.ts +35 -158
  202. package/template/server/src/test/setup.ts +3 -10
  203. package/template/server/tsconfig.build.json +1 -1
  204. package/template/server/tsconfig.json +1 -0
  205. package/template/server/vitest.config.ts +17 -4
  206. package/template/server/vitest.integration.config.ts +18 -13
  207. package/template/server/src/libs/storage/filename-sanitizer.ts +0 -71
@@ -100,12 +100,38 @@ export async function connectRedis(): Promise<boolean> {
100
100
  await client.connect();
101
101
  return true;
102
102
  } catch (error) {
103
- logger.warn('[REDIS] Initial connection failed — server starts without Redis and keeps retrying in the background');
103
+ // What happens next is server.ts's call: production waits a little, then
104
+ // refuses to start; elsewhere the server starts without Redis.
105
+ logger.warn('[REDIS] Initial connection failed — retrying in the background');
104
106
  logger.debug(error);
105
107
  return false;
106
108
  }
107
109
  }
108
110
 
111
+ /**
112
+ * Resolves true as soon as the client is ready (connected and usable), or
113
+ * false once `timeoutMs` has passed without that. Never throws; the connection
114
+ * keeps retrying in the background either way (see getRedis). server.ts uses
115
+ * it at boot in production, where an unreachable Redis must stop the start.
116
+ */
117
+ export function waitForRedisReady(
118
+ timeoutMs: number,
119
+ client: Pick<Redis, 'status' | 'once' | 'off'> = getRedis(),
120
+ ): Promise<boolean> {
121
+ if (client.status === 'ready') return Promise.resolve(true);
122
+ return new Promise((resolve) => {
123
+ const onReady = (): void => {
124
+ clearTimeout(timer);
125
+ resolve(true);
126
+ };
127
+ const timer = setTimeout(() => {
128
+ client.off('ready', onReady);
129
+ resolve(false);
130
+ }, timeoutMs);
131
+ client.once('ready', onReady);
132
+ });
133
+ }
134
+
109
135
  export async function disconnectRedis(): Promise<void> {
110
136
  if (redis) {
111
137
  const client = redis;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The id that ties one request's log lines, error report and response together
3
+ * (logged as reqId, echoed as the `x-request-id` response header).
4
+ *
5
+ * An inbound X-Request-Id is honoured so a proxy in front can pass its own id
6
+ * along, but only when it is short and plain: anyone can send that header, and
7
+ * the value lands in every log line of the request and in the response. A
8
+ * 16 KB id would bloat the logs; a reused one would make an attacker's requests
9
+ * look like part of someone else's trace. Anything else gets a fresh UUID.
10
+ */
11
+ import { randomUUID } from 'node:crypto';
12
+
13
+ /** Up to 128 letters, digits, dots, underscores or dashes (covers UUIDs and proxy ids). */
14
+ export const REQUEST_ID_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
15
+
16
+ export function requestIdFrom(header: string | string[] | undefined): string {
17
+ return typeof header === 'string' && REQUEST_ID_PATTERN.test(header) ? header : randomUUID();
18
+ }
@@ -1,4 +1,5 @@
1
1
  import type { FastifyRequest, FastifyReply } from 'fastify';
2
+ import { env } from '@config/env.js';
2
3
  import { logger } from '@libs/logger.js';
3
4
  import { getClientIp } from '@libs/client-ip.js';
4
5
 
@@ -22,6 +23,30 @@ const colors = {
22
23
  reset: '\x1b[0m',
23
24
  };
24
25
 
26
+ /**
27
+ * Whether request lines get terminal colours. Only for a developer watching a
28
+ * real terminal: in production pino writes JSON, where escape codes would end
29
+ * up as literal `\u001b[34m` junk inside `msg` (Coolify and log search show
30
+ * them verbatim). Production never gets colours, even if stdout is a TTY.
31
+ */
32
+ export function shouldColorize(isTty: boolean | undefined, nodeEnv: string): boolean {
33
+ return isTty === true && nodeEnv !== 'production';
34
+ }
35
+
36
+ /**
37
+ * Whether request lines carry their parts as separate JSON fields. Only where
38
+ * logs are JSON (production, the same switch as the pino-pretty transport in
39
+ * logger.ts): pino-pretty would print each field on its own line under every
40
+ * request, while a developer reads the one-line summary anyway.
41
+ */
42
+ export function shouldAttachFields(nodeEnv: string): boolean {
43
+ return nodeEnv === 'production';
44
+ }
45
+
46
+ // Decided once at startup: neither stdout nor NODE_ENV changes at runtime.
47
+ const useColor = shouldColorize(process.stdout.isTTY, env.NODE_ENV);
48
+ const attachFields = shouldAttachFields(env.NODE_ENV);
49
+
25
50
  function getStatusColor(statusCode: number): string {
26
51
  if (statusCode >= 500) return colors.serverError;
27
52
  if (statusCode >= 400) return colors.clientError;
@@ -35,6 +60,66 @@ function formatDuration(ms: number): string {
35
60
  return `${(ms / 1000).toFixed(2)}s`;
36
61
  }
37
62
 
63
+ export interface RequestLineParts {
64
+ method: string;
65
+ url: string;
66
+ statusCode: number;
67
+ statusMessage: string;
68
+ durationMs: number;
69
+ clientIp: string;
70
+ requestId: string;
71
+ }
72
+
73
+ /**
74
+ * The URL without its query string or fragment. Queries carry search terms,
75
+ * email addresses and the like (`/admin/users?search=jane@example.com`), and
76
+ * links in emails carry tokens, so no request log keeps them; route params
77
+ * stay (they are ids, not secrets).
78
+ */
79
+ export function requestPath(url: string): string {
80
+ const end = url.search(/[?#]/);
81
+ return end === -1 ? url : url.slice(0, end);
82
+ }
83
+
84
+ /** The request line's parts as JSON fields, for searching and alerting on production logs. */
85
+ export interface RequestLogFields {
86
+ reqId: string;
87
+ method: string;
88
+ path: string;
89
+ statusCode: number;
90
+ durationMs: number;
91
+ ip: string;
92
+ }
93
+
94
+ export function requestLogFields(parts: RequestLineParts): RequestLogFields {
95
+ return {
96
+ reqId: parts.requestId,
97
+ method: parts.method,
98
+ path: requestPath(parts.url),
99
+ statusCode: parts.statusCode,
100
+ durationMs: parts.durationMs,
101
+ ip: parts.clientIp,
102
+ };
103
+ }
104
+
105
+ /**
106
+ * Build the one-line summary. Pure (no I/O), so the colour rule is testable.
107
+ * With `color: false` the line contains no escape codes at all. The URL is
108
+ * printed without its query (requestPath).
109
+ */
110
+ export function formatRequestLine(parts: RequestLineParts, { color }: { color: boolean }): string {
111
+ const paint = (code: string, text: string): string => (color ? `${code}${text}${colors.reset}` : text);
112
+ const methodColor = colors[parts.method as keyof typeof colors] || colors.reset;
113
+
114
+ return [
115
+ paint(methodColor, parts.method.padEnd(7)),
116
+ `${requestPath(parts.url)} `,
117
+ paint(getStatusColor(parts.statusCode), `${parts.statusCode} ${parts.statusMessage}`),
118
+ ' ',
119
+ paint(colors.dim, `(${formatDuration(parts.durationMs)}) [ip=${parts.clientIp} reqId=${parts.requestId}]`),
120
+ ].join('');
121
+ }
122
+
38
123
  /**
39
124
  * Mark request start time (called in preHandler)
40
125
  */
@@ -46,27 +131,37 @@ export function markRequestStart(request: FastifyRequest): void {
46
131
  * Log a single-line request/response summary (called in onResponse)
47
132
  *
48
133
  * Format: GET /api/v1/auth/me 200 OK (12ms) [ip=203.0.113.7 reqId=<uuid>]
134
+ * In production the same parts also go out as JSON fields
135
+ * ({ reqId, method, path, statusCode, durationMs, ip }), so log search can
136
+ * filter on them instead of parsing the text. Neither keeps the query string.
49
137
  *
50
- * The IP is the Cloudflare-/proxy-aware resolved client IP (getClientIp), so
51
- * behind Cloudflare we log the CF-Connecting-IP, not the shared edge IP. reqId
52
- * is request.id (inbound X-Request-Id or the minted UUID) for log↔Sentry tie-up.
138
+ * The IP is the proxy-aware resolved client IP (getClientIp): the verified
139
+ * CF-Connecting-IP behind Cloudflare, otherwise the address our own proxy saw.
140
+ * reqId is request.id (inbound X-Request-Id or the minted UUID) for log↔Sentry
141
+ * tie-up. Colours follow shouldColorize(); production lines are plain text.
142
+ * `options` exists for tests; the app always uses the startup decision.
53
143
  */
54
- export function logRequestLine(request: FastifyRequest, reply: FastifyReply): void {
55
- const duration = request.startTime ? Date.now() - request.startTime : 0;
144
+ export function logRequestLine(
145
+ request: FastifyRequest,
146
+ reply: FastifyReply,
147
+ options: { color: boolean; fields: boolean } = { color: useColor, fields: attachFields },
148
+ ): void {
56
149
  const statusCode = reply.statusCode;
57
- const statusMessage = reply.raw.statusMessage || '';
58
- const clientIp = getClientIp(request);
59
-
60
- const methodColor = colors[request.method as keyof typeof colors] || colors.reset;
61
- const statusColor = getStatusColor(statusCode);
62
-
63
- const line = `${methodColor}${request.method.padEnd(7)}${colors.reset}${request.url} ${statusColor}${statusCode} ${statusMessage}${colors.reset} ${colors.dim}(${formatDuration(duration)}) [ip=${clientIp} reqId=${request.id}]${colors.reset}`;
150
+ const parts: RequestLineParts = {
151
+ method: request.method,
152
+ url: request.url,
153
+ statusCode,
154
+ statusMessage: reply.raw.statusMessage || '',
155
+ durationMs: request.startTime ? Date.now() - request.startTime : 0,
156
+ clientIp: getClientIp(request),
157
+ requestId: String(request.id),
158
+ };
159
+ const line = formatRequestLine(parts, { color: options.color });
160
+ const level = statusCode >= 500 ? 'error' : statusCode >= 400 ? 'warn' : 'info';
64
161
 
65
- if (statusCode >= 500) {
66
- logger.error(line);
67
- } else if (statusCode >= 400) {
68
- logger.warn(line);
162
+ if (options.fields) {
163
+ logger[level](requestLogFields(parts), line);
69
164
  } else {
70
- logger.info(line);
165
+ logger[level](line);
71
166
  }
72
167
  }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The guarded outbound client for URLs that came from a user (an avatar or
3
+ * import "from a link", webhooks, link previews). A URL like that must never
4
+ * reach the database, Redis, Coolify's internal services or a cloud metadata
5
+ * endpoint (SSRF). Trusted, hard-coded URLs use httpClient (libs/http.ts).
6
+ *
7
+ * Every connection is checked, not just the URL as written:
8
+ * - http: and https: only (no file:, data:, ftp:, ...);
9
+ * - an IP literal in the URL (first hop, or any redirect hop) must be a public
10
+ * address (isForbiddenOutboundIp, libs/url-safety.ts);
11
+ * - a hostname is resolved by our own lookup, which refuses it when ANY answer
12
+ * is not public, and the socket then connects to exactly the addresses that
13
+ * were checked: a DNS answer cannot change between the check and the
14
+ * connection (DNS rebinding);
15
+ * - redirects: at most 3, each hop checked the same way;
16
+ * - environment proxies are ignored (with a proxy the lookup would check the
17
+ * proxy, and the proxy would fetch the internal target for us);
18
+ * - 10 s timeout, 10 MB body cap (createHttpClient).
19
+ *
20
+ * A refused request throws OutboundHttpError with kind 'blocked' (a generic 500
21
+ * unless the caller handles it, e.g. as "this link is not allowed").
22
+ */
23
+ import dns, { type LookupAddress } from 'node:dns';
24
+ import { isIP } from 'node:net';
25
+ import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
26
+ import { createHttpClient, OutboundHttpError, OUTBOUND_BLOCKED } from '@libs/http.js';
27
+ import { isForbiddenOutboundIp } from '@libs/url-safety.js';
28
+
29
+ const SAFE_TIMEOUT_MS = 10_000;
30
+ const MAX_REDIRECTS = 3;
31
+
32
+ type Resolve = (hostname: string, options: { all: true; family?: number }) => Promise<LookupAddress[]>;
33
+
34
+ const systemResolve: Resolve = (hostname, options) => dns.promises.lookup(hostname, options);
35
+
36
+ /** The error our guards raise inside axios (recognised by libs/http.ts as kind 'blocked'). */
37
+ function blocked(): Error {
38
+ return Object.assign(new Error('Outbound request refused: the target is not a public address'), {
39
+ code: OUTBOUND_BLOCKED,
40
+ });
41
+ }
42
+
43
+ /** The hostname as an IP literal (brackets stripped), or null when it is a name. */
44
+ function literalIp(hostname: string): string | null {
45
+ const host = hostname.replace(/^\[|\]$/g, '');
46
+ return isIP(host) ? host : null;
47
+ }
48
+
49
+ /** Whether a target (protocol + hostname) may be connected to, before any DNS. */
50
+ function isAllowedTarget(protocol: string, hostname: string, isForbidden: (ip: string) => boolean): boolean {
51
+ if (protocol !== 'http:' && protocol !== 'https:') return false;
52
+ const ip = literalIp(hostname);
53
+ return ip === null || !isForbidden(ip);
54
+ }
55
+
56
+ export interface SafeHttpOptions {
57
+ /** DNS resolver (tests inject one). */
58
+ resolve?: Resolve;
59
+ /** Address policy (tests may loosen it for a local server; production never). */
60
+ isForbidden?: (ip: string) => boolean;
61
+ }
62
+
63
+ export function createSafeHttpClient({
64
+ resolve = systemResolve,
65
+ isForbidden = isForbiddenOutboundIp,
66
+ }: SafeHttpOptions = {}): AxiosInstance {
67
+ // Every hostname connection resolves here; the socket uses only checked addresses.
68
+ const lookup = async (hostname: string, options: { family?: number } = {}): Promise<LookupAddress[]> => {
69
+ const answers = await resolve(hostname, { all: true, family: options.family || undefined });
70
+ if (answers.length === 0 || answers.some((answer) => isForbidden(answer.address))) throw blocked();
71
+ return answers;
72
+ };
73
+
74
+ const client = createHttpClient({
75
+ timeout: SAFE_TIMEOUT_MS,
76
+ maxRedirects: MAX_REDIRECTS,
77
+ proxy: false,
78
+ lookup,
79
+ // Redirect hops: an IP literal skips the lookup, so check it (and the protocol) here.
80
+ beforeRedirect: (options) => {
81
+ if (!isAllowedTarget(String(options.protocol), String(options.hostname), isForbidden)) throw blocked();
82
+ },
83
+ });
84
+
85
+ // First hop: refuse before anything is sent (an IP literal never reaches the lookup).
86
+ client.interceptors.request.use((config: InternalAxiosRequestConfig): InternalAxiosRequestConfig => {
87
+ let target: URL;
88
+ try {
89
+ target = new URL(String(config.url), config.baseURL);
90
+ } catch {
91
+ throw new OutboundHttpError('blocked');
92
+ }
93
+ if (!isAllowedTarget(target.protocol, target.hostname, isForbidden)) throw new OutboundHttpError('blocked');
94
+ return config;
95
+ });
96
+
97
+ return client;
98
+ }
99
+
100
+ /** For URLs a user supplied. Trusted, hard-coded URLs: httpClient (libs/http.ts). */
101
+ export const safeHttpClient: AxiosInstance = createSafeHttpClient();
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Process shutdown with honest exit codes and a deadline (wired in server.ts).
3
+ *
4
+ * Exit codes are how Docker, Coolify and any restart policy tell a deploy or a
5
+ * stop from a crash:
6
+ * - SIGTERM / SIGINT (a deploy, `docker stop`, Ctrl+C): 0 once everything closed;
7
+ * - an uncaught exception, an unhandled rejection or a failed start: 1, even
8
+ * when the cleanup itself went fine (it used to be 0, so a crash or a server
9
+ * that never started looked like a clean stop);
10
+ * - a cleanup that throws: 1.
11
+ *
12
+ * The deadline: `docker stop` (and Coolify's rolling updates) wait 10 s after
13
+ * SIGTERM, then SIGKILL, which skips every log line. If closing hangs (a
14
+ * request that never ends, a database that does not answer), the process logs
15
+ * a fatal line and exits 1 at SHUTDOWN_DEADLINE_MS instead, inside that window.
16
+ */
17
+ import type { Logger } from 'pino';
18
+
19
+ export type ShutdownReason =
20
+ | 'SIGINT'
21
+ | 'SIGTERM'
22
+ | 'uncaughtException'
23
+ | 'unhandledRejection'
24
+ | 'startup-error';
25
+
26
+ /** Reasons that mean something went wrong: the process exits 1 whatever the cleanup does. */
27
+ const FAILURE_REASONS: ReadonlySet<ShutdownReason> = new Set([
28
+ 'uncaughtException',
29
+ 'unhandledRejection',
30
+ 'startup-error',
31
+ ]);
32
+
33
+ /** Below Docker's default 10 s stop timeout, so our own fatal line is written before SIGKILL. */
34
+ export const SHUTDOWN_DEADLINE_MS = 8_000;
35
+
36
+ export interface ShutdownOptions {
37
+ /** Closes the app, then Redis, then the database. */
38
+ close: () => Promise<void>;
39
+ /** process.exit in production; a spy in tests. */
40
+ exit: (code: number) => void;
41
+ logger: Pick<Logger, 'info' | 'error' | 'fatal'>;
42
+ deadlineMs?: number;
43
+ }
44
+
45
+ /**
46
+ * Returns the one shutdown function for the process. Only the first call
47
+ * closes anything; later calls (a second signal, an exception thrown while
48
+ * closing) start nothing new, but a failure reason arriving later still turns
49
+ * the final exit code into 1.
50
+ *
51
+ * The deadline timer is deliberately NOT unref'd: every path ends in exit(),
52
+ * so it never keeps a finished process alive, and if close() hung with nothing
53
+ * else holding the event loop, an unref'd timer would let Node end on its own
54
+ * with exit code 0.
55
+ */
56
+ export function createShutdown({
57
+ close,
58
+ exit,
59
+ logger,
60
+ deadlineMs = SHUTDOWN_DEADLINE_MS,
61
+ }: ShutdownOptions): (reason: ShutdownReason) => Promise<void> {
62
+ let started = false;
63
+ let failed = false;
64
+
65
+ return async function shutdown(reason: ShutdownReason): Promise<void> {
66
+ if (FAILURE_REASONS.has(reason)) failed = true;
67
+ if (started) return;
68
+ started = true;
69
+
70
+ logger.info(`[SERVER] Received ${reason} - shutting down gracefully`);
71
+ const deadline = setTimeout(() => {
72
+ logger.fatal(`[SERVER] Shutdown did not finish within ${deadlineMs / 1000}s; exiting`);
73
+ exit(1);
74
+ }, deadlineMs);
75
+
76
+ try {
77
+ await close();
78
+ clearTimeout(deadline);
79
+ logger.info('[SERVER] Shutdown complete');
80
+ exit(failed ? 1 : 0);
81
+ } catch (error) {
82
+ clearTimeout(deadline);
83
+ logger.error({ err: error }, '[SERVER] Error during shutdown');
84
+ exit(1);
85
+ }
86
+ };
87
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A real HEIC (HEVC-coded HEIF, brand 'heic'): 16x16 solid colour, 467 bytes, no
3
+ * EXIF/XMP. Generated with pillow-heif (libheif 1.23 + x265); it is not a photo.
4
+ * The same bytes are embedded in scripts/check-heic.mjs (the image build check).
5
+ */
6
+ export const TINY_HEIC_BASE64 =
7
+ 'AAAAHGZ0eXBoZWljAAAAAG1pZjFoZWljbWlhZgAAAXxtZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAA' +
8
+ 'ACJpbG9jAAAAAERAAAEAAQAAAAABoAABAAAAAAAAADMAAAAjaWluZgAAAAAAAQAAABVpbmZlAgAAAAABAABodmMxAAAAAA5waXRt' +
9
+ 'AAAAAAABAAAA/GlwcnAAAADcaXBjbwAAAHVodmNDAQNwAAAAkAAAAAAAHvAA/P34+AAADwNgAAEAGEABDAH//wNwAAADAJAAAAMA' +
10
+ 'AAMAHroCQGEAAQApQgEBA3AAAAMAkAAAAwAAAwAeoCCBBZbqrprm4CGgwIAAAAyAAAADAIRiAAEABkQBwXPBiQAAABNjb2xybmNs' +
11
+ 'eAABAA0ABoAAAAAUaXNwZQAAAAAAAABAAAAAQAAAAChjbGFwAAAAEAAAAAEAAAAQAAAAAf///9AAAAAC////0AAAAAIAAAAQcGl4' +
12
+ 'aQAAAAADCAgIAAAAGGlwbWEAAAAAAAAAAQABBYECAwWEAAAAO21kYXQAAAAvKAGvEyFkY0D4EPdn/9RdjB6iuj/gbsenOyEdwNIg' +
13
+ 'gJtASJNdUAsWEICHdqVW3Pg=';
@@ -2,6 +2,9 @@ import { describe, it, expect } from 'vitest';
2
2
  import { crc32, deflateSync } from 'node:zlib';
3
3
  import sharp from 'sharp';
4
4
  import { imageOptimizerService, MAX_INPUT_PIXELS } from '../image-optimizer.service.js';
5
+ import { validateFileSize, validateImageFile } from '../file-validator.js';
6
+ import { TINY_HEIC_BASE64 } from './fixtures/tiny-heic.js';
7
+ import type { MultipartFile } from '@fastify/multipart';
5
8
 
6
9
  // Avatars are public: the output must carry no metadata (GPS, device), and a
7
10
  // small file describing a huge picture must be refused before it is decoded.
@@ -68,10 +71,38 @@ describe('imageOptimizerService.optimizeAvatar', () => {
68
71
  it('refuses formats outside the allowlist even when named like a PNG', async () => {
69
72
  const gif = await sharp({ create: { width: 8, height: 8, channels: 3, background: '#ff0000' } }).gif().toBuffer();
70
73
  await expect(imageOptimizerService.optimizeAvatar(gif)).rejects.toMatchObject({
74
+ statusCode: 422,
71
75
  code: 'UNSUPPORTED_IMAGE_FORMAT',
76
+ message: 'Image format is not supported. Use JPEG, PNG, WebP or HEIC.',
72
77
  });
73
78
  });
74
79
 
80
+ it('refuses bytes that are not an image at all (a text file named photo.jpg)', async () => {
81
+ await expect(imageOptimizerService.optimizeAvatar(Buffer.from('not an image, just text'))).rejects.toMatchObject({
82
+ statusCode: 422,
83
+ });
84
+ });
85
+
86
+ it('accepts AVIF (sharp reports it as heif, and every build decodes it)', async () => {
87
+ const avif = await sharp({ create: { width: 16, height: 16, channels: 3, background: '#20a040' } }).avif().toBuffer();
88
+ const meta = await sharp(await imageOptimizerService.optimizeAvatar(avif)).metadata();
89
+ expect(meta.format).toBe('webp');
90
+ });
91
+
92
+ it('a real HEIC decodes where the build has HEVC (the Docker image), else answers 422, never a 500', async () => {
93
+ const heic = Buffer.from(TINY_HEIC_BASE64, 'base64');
94
+ expect((await sharp(heic).metadata()).compression).toBe('hevc');
95
+ // sharp's prebuilt binaries (developer machines) cannot decode HEVC; the
96
+ // server image can, and scripts/check-heic.mjs proves it at build time.
97
+ const canDecodeHevc = await sharp(heic).resize(1, 1).toBuffer().then(() => true, () => false);
98
+ const result = imageOptimizerService.optimizeAvatar(heic);
99
+ if (canDecodeHevc) {
100
+ expect((await sharp(await result).metadata()).format).toBe('webp');
101
+ } else {
102
+ await expect(result).rejects.toMatchObject({ statusCode: 422, code: 'UNSUPPORTED_IMAGE_FORMAT' });
103
+ }
104
+ });
105
+
75
106
  it('accepts a normal photo-sized JPEG', async () => {
76
107
  const photo = await sharp({ create: { width: 4000, height: 3000, channels: 3, background: '#336699' } })
77
108
  .jpeg()
@@ -82,3 +113,31 @@ describe('imageOptimizerService.optimizeAvatar', () => {
82
113
  expect(meta.height).toBe(384);
83
114
  });
84
115
  });
116
+
117
+ describe('validateImageFile', () => {
118
+ const file = (mimetype: string, filename: string): MultipartFile => ({ mimetype, filename }) as unknown as MultipartFile;
119
+
120
+ it('ignores the browser-sent type and name: the bytes decide later', () => {
121
+ expect(() => validateImageFile(file('application/octet-stream', 'blob'))).not.toThrow();
122
+ expect(() => validateImageFile(file('image/heic', 'IMG_0001.HEIC'))).not.toThrow();
123
+ expect(() => validateImageFile(file('application/x-msdownload', 'photo.exe'))).not.toThrow();
124
+ });
125
+
126
+ it('refuses an upload without a file', () => {
127
+ expect(() => validateImageFile(undefined)).toThrow(expect.objectContaining({ code: 'FILE_REQUIRED' }));
128
+ });
129
+ });
130
+
131
+ describe('validateFileSize', () => {
132
+ it('refuses a file the parser cut at the size limit with 413 FILE_TOO_LARGE, whatever its length', () => {
133
+ // The cut file is exactly MAX_FILE_SIZE bytes, so a length check alone lets it through.
134
+ expect(() => validateFileSize(Buffer.alloc(16), true)).toThrow(
135
+ expect.objectContaining({ statusCode: 413, code: 'FILE_TOO_LARGE' }),
136
+ );
137
+ });
138
+
139
+ it('accepts a complete file and refuses an empty one', () => {
140
+ expect(() => validateFileSize(Buffer.alloc(16), false)).not.toThrow();
141
+ expect(() => validateFileSize(Buffer.alloc(0), false)).toThrow(expect.objectContaining({ code: 'FILE_EMPTY' }));
142
+ });
143
+ });
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Multipart limits (MULTIPART_LIMITS in ../file-validator.ts) on a small Fastify
3
+ * app wired like src/app.ts: the real @fastify/multipart plugin, the same limits
4
+ * and the global error handler. Form fields sent before the file are buffered,
5
+ * so their number and size must be capped, and going over must be a clear 413,
6
+ * never a 500 and never "your file is too large".
7
+ */
8
+ import Fastify, { type FastifyInstance } from 'fastify';
9
+ import multipart from '@fastify/multipart';
10
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
11
+ import { registerErrorHandler } from '@libs/error-handler.js';
12
+ import { MULTIPART_LIMITS } from '../file-validator.js';
13
+
14
+ const FILE_SIZE = 64 * 1024;
15
+ let app: FastifyInstance;
16
+
17
+ beforeAll(async () => {
18
+ app = Fastify({ logger: false });
19
+ registerErrorHandler(app);
20
+ await app.register(multipart, { limits: { fileSize: FILE_SIZE, files: 1, ...MULTIPART_LIMITS } });
21
+ // Like the avatar upload: take the first file, read it whole.
22
+ app.post('/upload', async (request) => {
23
+ const file = await request.file();
24
+ const bytes = file ? (await file.toBuffer()).length : 0;
25
+ const fields = file ? Object.values(file.fields).filter((f) => f && 'value' in f) : [];
26
+ const longest = Math.max(0, ...fields.map((f) => String((f as { value: unknown }).value).length));
27
+ return { bytes, fields: fields.length, longest };
28
+ });
29
+ await app.ready();
30
+ });
31
+
32
+ afterAll(async () => {
33
+ await app.close();
34
+ });
35
+
36
+ /** A multipart body: `fields` text fields of `fieldBytes` each, then `files` small files. */
37
+ function form(fields: number, fieldBytes = 10, files = 1, fileBytes = 100): { payload: Buffer; headers: Record<string, string> } {
38
+ const boundary = 'limits-test-boundary';
39
+ const parts: Buffer[] = [];
40
+ for (let i = 0; i < fields; i++) {
41
+ parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="f${i}"\r\n\r\n${'a'.repeat(fieldBytes)}\r\n`));
42
+ }
43
+ for (let i = 0; i < files; i++) {
44
+ parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="file${i}"; filename="a${i}.bin"\r\nContent-Type: application/octet-stream\r\n\r\n`));
45
+ parts.push(Buffer.alloc(fileBytes, 1), Buffer.from('\r\n'));
46
+ }
47
+ parts.push(Buffer.from(`--${boundary}--\r\n`));
48
+ return { payload: Buffer.concat(parts), headers: { 'content-type': `multipart/form-data; boundary=${boundary}` } };
49
+ }
50
+
51
+ describe('multipart limits', () => {
52
+ it('a normal upload with a few small fields still works', async () => {
53
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(2) });
54
+ expect(res.statusCode).toBe(200);
55
+ expect(res.json()).toMatchObject({ bytes: 100, fields: 2 });
56
+ });
57
+
58
+ it('more fields than allowed answers 413 MULTIPART_LIMIT, not FILE_TOO_LARGE', async () => {
59
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(MULTIPART_LIMITS.fields + 1) });
60
+ expect(res.statusCode).toBe(413);
61
+ expect(res.json().error).toEqual({ code: 'MULTIPART_LIMIT', message: 'Too many form fields or files in this upload' });
62
+ });
63
+
64
+ it('too many fields only (no file) answers the same 413', async () => {
65
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(MULTIPART_LIMITS.fields + 1, 10, 0) });
66
+ expect(res.statusCode).toBe(413);
67
+ expect(res.json().error.code).toBe('MULTIPART_LIMIT');
68
+ });
69
+
70
+ it('a second file is ignored: only the first is read, never a 500', async () => {
71
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(0, 0, 2) });
72
+ expect(res.statusCode).toBe(200);
73
+ expect(res.json()).toMatchObject({ bytes: 100 });
74
+ });
75
+
76
+ it('a field longer than fieldSize is cut at fieldSize, never kept whole', async () => {
77
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(1, MULTIPART_LIMITS.fieldSize * 3) });
78
+ expect(res.statusCode).toBe(200);
79
+ expect(res.json().longest).toBe(MULTIPART_LIMITS.fieldSize);
80
+ });
81
+
82
+ it('a file over the size limit still answers 413 FILE_TOO_LARGE', async () => {
83
+ const res = await app.inject({ method: 'POST', url: '/upload', ...form(0, 0, 1, FILE_SIZE + 1) });
84
+ expect(res.statusCode).toBe(413);
85
+ expect(res.json().error.code).toBe('FILE_TOO_LARGE');
86
+ });
87
+
88
+ it('caps fields at about 2 MB in total', () => {
89
+ expect(MULTIPART_LIMITS.fields * MULTIPART_LIMITS.fieldSize).toBeLessThanOrEqual(2 * 1024 * 1024);
90
+ });
91
+ });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The "uploads will be lost on the next deploy" check (uploadDirsOnContainerDisk
3
+ * in ../file-storage.service.ts) with a fake disk: it flags a folder only in
4
+ * production, only inside a Docker container, and only when the folder is on
5
+ * the container's own disk (same device as "/") rather than a mounted volume.
6
+ */
7
+ import { describe, expect, it } from 'vitest';
8
+ import { type DiskProbe, uploadDirsOnContainerDisk } from '../file-storage.service.js';
9
+
10
+ const DIRS = ['/app/uploads/public', '/app/uploads/private'];
11
+
12
+ /** A fake disk: "/" is device 1; `mounted` folders live on device 2. */
13
+ function disk({ container = true, mounted = [] as string[], broken = [] as string[] } = {}): DiskProbe {
14
+ return {
15
+ exists: (p) => container && p === '/.dockerenv',
16
+ device: (p): number => {
17
+ if (broken.includes(p)) throw new Error('EACCES');
18
+ return mounted.some((m) => p === m || p.startsWith(`${m}/`)) ? 2 : 1;
19
+ },
20
+ };
21
+ }
22
+
23
+ describe('uploadDirsOnContainerDisk', () => {
24
+ it('flags both tiers in a production container without a volume', () => {
25
+ expect(uploadDirsOnContainerDisk(DIRS, 'production', disk())).toEqual(DIRS);
26
+ });
27
+
28
+ it('flags nothing when /app/uploads is a mounted volume', () => {
29
+ expect(uploadDirsOnContainerDisk(DIRS, 'production', disk({ mounted: ['/app/uploads'] }))).toEqual([]);
30
+ });
31
+
32
+ it('flags only the tier that is not on the volume', () => {
33
+ expect(uploadDirsOnContainerDisk(DIRS, 'production', disk({ mounted: ['/app/uploads/public'] }))).toEqual([
34
+ '/app/uploads/private',
35
+ ]);
36
+ });
37
+
38
+ it('never flags in development or test', () => {
39
+ expect(uploadDirsOnContainerDisk(DIRS, 'development', disk())).toEqual([]);
40
+ expect(uploadDirsOnContainerDisk(DIRS, 'test', disk())).toEqual([]);
41
+ });
42
+
43
+ it('never flags outside a container (a plain server disk is persistent)', () => {
44
+ expect(uploadDirsOnContainerDisk(DIRS, 'production', disk({ container: false }))).toEqual([]);
45
+ });
46
+
47
+ it('leaves out a folder it cannot check instead of guessing', () => {
48
+ expect(uploadDirsOnContainerDisk(DIRS, 'production', disk({ broken: ['/app/uploads/public'] }))).toEqual([
49
+ '/app/uploads/private',
50
+ ]);
51
+ });
52
+ });