ddd-ts-kit 0.8.0 → 0.9.0
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.
- package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
- package/dist/check/catalogue/architecture-rules.js +4 -0
- package/dist/check/catalogue/architecture-rules.js.map +1 -1
- package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
- package/dist/check/errors/kit-error-codes.js +5 -0
- package/dist/check/errors/kit-error-codes.js.map +1 -1
- package/dist/check/explain/errors-docs.js +1 -1
- package/dist/check/explain/errors-docs.js.map +1 -1
- package/dist/check/explain/persistence-docs.d.ts.map +1 -1
- package/dist/check/explain/persistence-docs.js +26 -0
- package/dist/check/explain/persistence-docs.js.map +1 -1
- package/dist/check/files/file-content-findings.d.ts +4 -0
- package/dist/check/files/file-content-findings.d.ts.map +1 -0
- package/dist/check/files/file-content-findings.js +29 -0
- package/dist/check/files/file-content-findings.js.map +1 -0
- package/dist/check/files/file-content-pattern.d.ts +7 -0
- package/dist/check/files/file-content-pattern.d.ts.map +1 -0
- package/dist/check/files/file-content-pattern.js +17 -0
- package/dist/check/files/file-content-pattern.js.map +1 -0
- package/dist/check/files/schema-sources.d.ts +13 -0
- package/dist/check/files/schema-sources.d.ts.map +1 -0
- package/dist/check/files/schema-sources.js +37 -0
- package/dist/check/files/schema-sources.js.map +1 -0
- package/dist/check/fixtures/files-fixtures.d.ts +3 -0
- package/dist/check/fixtures/files-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/files-fixtures.js +92 -0
- package/dist/check/fixtures/files-fixtures.js.map +1 -0
- package/dist/check/fixtures/fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/fixtures.js +2 -0
- package/dist/check/fixtures/fixtures.js.map +1 -1
- package/dist/check/layers/outside-concern.d.ts.map +1 -1
- package/dist/check/layers/outside-concern.js +4 -0
- package/dist/check/layers/outside-concern.js.map +1 -1
- package/dist/check/rules/files-port-not-connector.d.ts +3 -0
- package/dist/check/rules/files-port-not-connector.d.ts.map +1 -0
- package/dist/check/rules/files-port-not-connector.js +28 -0
- package/dist/check/rules/files-port-not-connector.js.map +1 -0
- package/dist/check/rules/persistence-no-file-content.d.ts +3 -0
- package/dist/check/rules/persistence-no-file-content.d.ts.map +1 -0
- package/dist/check/rules/persistence-no-file-content.js +14 -0
- package/dist/check/rules/persistence-no-file-content.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +1 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +2 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +8 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +1 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/generate/kinds/file-upload/write-upload-controller.d.ts +5 -0
- package/dist/generate/kinds/file-upload/write-upload-controller.d.ts.map +1 -0
- package/dist/generate/kinds/file-upload/write-upload-controller.js +42 -0
- package/dist/generate/kinds/file-upload/write-upload-controller.js.map +1 -0
- package/dist/generate/kinds/file-upload-kind.d.ts +3 -0
- package/dist/generate/kinds/file-upload-kind.d.ts.map +1 -0
- package/dist/generate/kinds/file-upload-kind.js +55 -0
- package/dist/generate/kinds/file-upload-kind.js.map +1 -0
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +2 -0
- package/dist/generate/kinds.js.map +1 -1
- package/dist/help/usage.d.ts +1 -1
- package/dist/help/usage.d.ts.map +1 -1
- package/dist/help/usage.js +2 -1
- package/dist/help/usage.js.map +1 -1
- package/dist/init/files/platform-files.d.ts.map +1 -1
- package/dist/init/files/platform-files.js +22 -0
- package/dist/init/files/platform-files.js.map +1 -1
- package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
- package/dist/init/manifest/dependencies-for.js +7 -1
- package/dist/init/manifest/dependencies-for.js.map +1 -1
- package/dist/init/manifest/versions.d.ts.map +1 -1
- package/dist/init/manifest/versions.js +28 -23
- package/dist/init/manifest/versions.js.map +1 -1
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +11 -2
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +1 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/init/template-vars.d.ts.map +1 -1
- package/dist/init/template-vars.js +3 -2
- package/dist/init/template-vars.js.map +1 -1
- package/dist/stack/files-vars.d.ts +5 -0
- package/dist/stack/files-vars.d.ts.map +1 -0
- package/dist/stack/files-vars.js +11 -0
- package/dist/stack/files-vars.js.map +1 -0
- package/dist/stack/stack-vars.d.ts.map +1 -1
- package/dist/stack/stack-vars.js +13 -4
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/templates/file-upload/command.ts.tpl +41 -0
- package/templates/file-upload/controller.spec.ts.tpl +46 -0
- package/templates/file-upload/controller.ts.tpl +23 -0
- package/templates/file-upload/handler.declared.ts.tpl +18 -0
- package/templates/file-upload/handler.spec.ts.tpl +79 -0
- package/templates/file-upload/handler.ts.tpl +16 -0
- package/templates/file-upload/wiring.manual.tpl +9 -0
- package/templates/file-upload/wiring.tsyringe.tpl +7 -0
- package/templates/init/README.md.tpl +22 -0
- package/templates/init/docker/docker-compose.yml.tpl +25 -0
- package/templates/init/docker/env.example.tpl +21 -0
- package/templates/init/gitignore.tpl +3 -0
- package/templates/init/main.ts.tpl +6 -0
- package/templates/init/platform/auth/http-boundary.ts.tpl +25 -1
- package/templates/init/platform/buses/create-command-bus.ts.tpl +7 -1
- package/templates/init/platform/compose-application.manual.ts.tpl +25 -0
- package/templates/init/platform/compose-application.tsyringe.ts.tpl +31 -0
- package/templates/init/platform/config/app-config.ts.tpl +7 -0
- package/templates/init/platform/config/load-config.ts.tpl +9 -0
- package/templates/init/platform/config/read-files.local.ts.tpl +39 -0
- package/templates/init/platform/config/read-files.s3.ts.tpl +42 -0
- package/templates/init/platform/create-platform.manual.ts.tpl +38 -1
- package/templates/init/platform/files/bind-files.tsyringe.ts.tpl +32 -0
- package/templates/init/platform/files/create-files.ts.tpl +34 -0
- package/templates/init/platform/files/file-routes.ts.tpl +10 -0
- package/templates/init/platform/files/files.module.tsyringe.ts.tpl +18 -0
- package/templates/init/platform/files/open-files.local.ts.tpl +13 -0
- package/templates/init/platform/files/open-files.s3.ts.tpl +10 -0
- package/templates/init/platform/files/staging-uploads.tsyringe.ts.tpl +11 -0
- package/templates/init/platform/http/start-http-server.express.ts.tpl +5 -1
- package/templates/init/platform/http/start-http-server.fastify.ts.tpl +4 -1
- package/templates/init/platform/http/start-http-server.nest.ts.tpl +12 -1
- package/templates/init/platform/platform-test.module.tsyringe.ts.tpl +11 -0
- package/templates/init/platform/platform.manual.ts.tpl +7 -0
- package/templates/init/rules/application.md.tpl +3 -0
- package/templates/init/rules/infrastructure.md.tpl +1 -0
- package/templates/init/rules/platform.md.tpl +3 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/service/main.ts.tpl +6 -0
- package/templates/worker/main.ts.tpl +6 -0
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import type { Authenticator } from '@ddd-ts-kit/auth';
|
|
2
2
|
{{#if errors.none}}
|
|
3
|
-
import type { ErrorContext, ErrorMapper, {{#if audit.on}}GuardRefusal, {{/if}}RouteAround } from '@ddd-ts-kit/http';
|
|
3
|
+
import type { ErrorContext, ErrorMapper, {{#if audit.on}}GuardRefusal, {{/if}}RouteAround{{#if files.http}}, UploadReader{{/if}} } from '@ddd-ts-kit/http';
|
|
4
4
|
import type { Clock, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
|
|
5
5
|
{{/if}}
|
|
6
6
|
{{#if errors.sentry}}
|
|
7
7
|
{{#unless audit.on}}
|
|
8
|
+
{{#unless files.http}}
|
|
8
9
|
import { reportHttpErrors, type ErrorContext, type ErrorMapper, type RouteAround } from '@ddd-ts-kit/http';
|
|
9
10
|
{{/unless}}
|
|
11
|
+
{{#if files.http}}
|
|
12
|
+
import {
|
|
13
|
+
reportHttpErrors,
|
|
14
|
+
type ErrorContext,
|
|
15
|
+
type ErrorMapper,
|
|
16
|
+
type RouteAround,
|
|
17
|
+
type UploadReader,
|
|
18
|
+
} from '@ddd-ts-kit/http';
|
|
19
|
+
{{/if}}
|
|
20
|
+
{{/unless}}
|
|
10
21
|
{{#if audit.on}}
|
|
11
22
|
import {
|
|
12
23
|
reportHttpErrors,
|
|
@@ -14,10 +25,16 @@ import {
|
|
|
14
25
|
type ErrorMapper,
|
|
15
26
|
type GuardRefusal,
|
|
16
27
|
type RouteAround,
|
|
28
|
+
{{#if files.http}}
|
|
29
|
+
type UploadReader,
|
|
30
|
+
{{/if}}
|
|
17
31
|
} from '@ddd-ts-kit/http';
|
|
18
32
|
{{/if}}
|
|
19
33
|
import type { Clock, ErrorReporter, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
|
|
20
34
|
{{/if}}
|
|
35
|
+
{{#if files.http}}
|
|
36
|
+
import { multipartUploads } from '@ddd-ts-kit/http/uploads';
|
|
37
|
+
{{/if}}
|
|
21
38
|
import { tracedRoutes } from '@ddd-ts-kit/tracing';
|
|
22
39
|
import { principalOf } from '{{alias.platform}}/auth/principal-of{{alias.ext}}';
|
|
23
40
|
|
|
@@ -32,6 +49,10 @@ export interface HttpBoundary {
|
|
|
32
49
|
readonly onError: (error: unknown, context: ErrorContext) => void;
|
|
33
50
|
/** The span of a request, named by its route template; probes and documentation routes make none. */
|
|
34
51
|
readonly around: RouteAround;
|
|
52
|
+
{{#if files.http}}
|
|
53
|
+
/** Reads the file of a controller that declares an upload, as it streams: its size and media types are checked on the way. */
|
|
54
|
+
readonly uploads: UploadReader;
|
|
55
|
+
{{/if}}
|
|
35
56
|
{{#if audit.on}}
|
|
36
57
|
/** A request a guard refused at the edge, written to the audit trail as a denied decision. */
|
|
37
58
|
readonly onGuardRefusal: (refusal: GuardRefusal) => Promise<void>;
|
|
@@ -91,6 +112,9 @@ export function httpBoundary({
|
|
|
91
112
|
errorMapper,
|
|
92
113
|
clock,
|
|
93
114
|
around: tracedRoutes(),
|
|
115
|
+
{{#if files.http}}
|
|
116
|
+
uploads: multipartUploads(),
|
|
117
|
+
{{/if}}
|
|
94
118
|
{{#if audit.on}}
|
|
95
119
|
onGuardRefusal: refusals,
|
|
96
120
|
{{/if}}
|
|
@@ -31,6 +31,9 @@ import {
|
|
|
31
31
|
} from '@ddd-ts-kit/kernel';
|
|
32
32
|
{{/unless}}
|
|
33
33
|
{{/if}}
|
|
34
|
+
{{#if files.any}}
|
|
35
|
+
import { stagingUploads } from '{{alias.platform}}/files/staging-uploads{{alias.ext}}';
|
|
36
|
+
{{/if}}
|
|
34
37
|
import type { Foundations } from '{{alias.platform}}/lay-foundations{{alias.ext}}';
|
|
35
38
|
{{#if cache.relaySignal}}
|
|
36
39
|
import type { RedisServices } from '{{alias.platform}}/redis/open-redis{{alias.ext}}';
|
|
@@ -48,7 +51,7 @@ interface Signalled {
|
|
|
48
51
|
* Around every command, outermost first: the report of an unexpected failure (a failed commit
|
|
49
52
|
* included), the log entry and the measure of the use case, the
|
|
50
53
|
{{/if}}
|
|
51
|
-
* permission, the span of the use case (a refused command never started){{#if cache.relaySignal}}, the wake-up of the outbox relay{{/if}}{{#if audit.on}}, the audit entry{{/if}}, then the unit of work. The guard and the unit of
|
|
54
|
+
* permission, the span of the use case (a refused command never started){{#if files.any}}, the staging of the file it carries{{/if}}{{#if cache.relaySignal}}, the wake-up of the outbox relay{{/if}}{{#if audit.on}}, the audit entry{{/if}}, then the unit of work. The guard and the unit of
|
|
52
55
|
* work are resolved at each command: building the bus must not open anything.{{#if audit.on}} The audit entry
|
|
53
56
|
* opens the transaction itself, so that the entry of a success commits with the state change
|
|
54
57
|
* and the entry of a failure survives the rollback.{{/if}}
|
|
@@ -69,6 +72,9 @@ export function createCommandBus(resolve: Resolve, foundations: Foundations): In
|
|
|
69
72
|
.use(metricsMiddleware(foundations.metrics))
|
|
70
73
|
.use((message, next, info) => resolve(UseCaseGuard).check(message, next, info))
|
|
71
74
|
.use(foundations.traced.useCase)
|
|
75
|
+
{{#if files.any}}
|
|
76
|
+
.use(stagingUploads(resolve))
|
|
77
|
+
{{/if}}
|
|
72
78
|
{{#if cache.relaySignal}}
|
|
73
79
|
.use(wakingTheRelay(options.redis))
|
|
74
80
|
{{/if}}
|
|
@@ -11,6 +11,9 @@ import { subscribeAll } from '@ddd-ts-kit/events';
|
|
|
11
11
|
{{#if http.any}}
|
|
12
12
|
import { createErrorMapper, defineRoutes, type Route } from '@ddd-ts-kit/http';
|
|
13
13
|
{{/if}}
|
|
14
|
+
{{#if files.any}}
|
|
15
|
+
import { PurgeStagedFiles } from '@ddd-ts-kit/kernel';
|
|
16
|
+
{{/if}}
|
|
14
17
|
{{#if cache.rateLimit}}
|
|
15
18
|
import type { IntegrationEventPublisher, IntegrationEventSubscriber, Logger, RateLimiter } from '@ddd-ts-kit/kernel';
|
|
16
19
|
{{/if}}
|
|
@@ -28,6 +31,9 @@ import { relateSystemActors } from '{{alias.platform}}/auth/relate-system-actors
|
|
|
28
31
|
{{/if}}
|
|
29
32
|
import { createPlatform, type PlatformOptions } from '{{alias.platform}}/create-platform{{alias.ext}}';
|
|
30
33
|
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
34
|
+
{{#if files.http}}
|
|
35
|
+
import { fileRoutes } from '{{alias.platform}}/files/file-routes{{alias.ext}}';
|
|
36
|
+
{{/if}}
|
|
31
37
|
import type { Platform } from '{{alias.platform}}/platform{{alias.ext}}';
|
|
32
38
|
// ddd-ts-kit:imports
|
|
33
39
|
// /ddd-ts-kit:imports
|
|
@@ -65,6 +71,10 @@ export interface Application {
|
|
|
65
71
|
/** Authenticates every request and runs it inside the execution scope. */
|
|
66
72
|
readonly boundary: HttpBoundary;
|
|
67
73
|
{{/if}}
|
|
74
|
+
{{#if files.http}}
|
|
75
|
+
/** The routes that answer the signed links of a storage the application serves itself; mounted before any body parser. */
|
|
76
|
+
readonly fileRoutes: readonly Route[];
|
|
77
|
+
{{/if}}
|
|
68
78
|
{{#unless http.any}}
|
|
69
79
|
readonly routes: readonly never[];
|
|
70
80
|
readonly contexts: readonly ContextWiring[];
|
|
@@ -101,6 +111,9 @@ export function composeApplication(
|
|
|
101
111
|
const { logger, metrics, cache, clock } = platform;
|
|
102
112
|
|
|
103
113
|
installAspectRuntime({ logger, metrics, cache, clock });
|
|
114
|
+
{{#if files.any}}
|
|
115
|
+
purgeStagedFiles(platform);
|
|
116
|
+
{{/if}}
|
|
104
117
|
|
|
105
118
|
{{#if audit.route}}
|
|
106
119
|
const contexts = [...selection, auditModule].map((module) => module(platform));
|
|
@@ -132,6 +145,9 @@ export function composeApplication(
|
|
|
132
145
|
routes: [],
|
|
133
146
|
contexts,
|
|
134
147
|
{{/unless}}
|
|
148
|
+
{{#if files.http}}
|
|
149
|
+
fileRoutes: fileRoutes(platform.files.storage),
|
|
150
|
+
{{/if}}
|
|
135
151
|
eventBus: platform.eventBus,
|
|
136
152
|
{{#if broker.external}}
|
|
137
153
|
// Behind a broker a listener has queues of its own, under its own name.
|
|
@@ -188,3 +204,12 @@ async function stop(platform: Platform, options: ApplicationOptions): Promise<vo
|
|
|
188
204
|
{{/if}}
|
|
189
205
|
await platform.logger.flush();
|
|
190
206
|
}
|
|
207
|
+
{{#if files.any}}
|
|
208
|
+
|
|
209
|
+
/** What rolled-back commands left in `staging/`, removed every hour by the process that runs the jobs. */
|
|
210
|
+
function purgeStagedFiles(platform: Platform): void {
|
|
211
|
+
const purge = new PurgeStagedFiles(platform.files.staging, platform.clock);
|
|
212
|
+
|
|
213
|
+
platform.jobs.register({ name: 'files.purge-staged', schedule: { every: '1h' }, run: () => purge.run() });
|
|
214
|
+
}
|
|
215
|
+
{{/if}}
|
|
@@ -38,11 +38,17 @@ import {
|
|
|
38
38
|
{{#if http.any}}
|
|
39
39
|
ExecutionScope,
|
|
40
40
|
{{/if}}
|
|
41
|
+
{{#if files.http}}
|
|
42
|
+
FileStorage,
|
|
43
|
+
{{/if}}
|
|
41
44
|
{{#if audit.on}}
|
|
42
45
|
{{#if http.any}}
|
|
43
46
|
IdGenerator,
|
|
44
47
|
{{/if}}
|
|
45
48
|
{{/if}}
|
|
49
|
+
{{#if files.any}}
|
|
50
|
+
InMemoryFileStorage,
|
|
51
|
+
{{/if}}
|
|
46
52
|
{{#unless broker.external}}
|
|
47
53
|
IntegrationEventSubscriber,
|
|
48
54
|
{{/unless}}
|
|
@@ -55,6 +61,11 @@ import {
|
|
|
55
61
|
RateLimiter,
|
|
56
62
|
{{/if}}
|
|
57
63
|
scopedPublisher,
|
|
64
|
+
{{#if files.any}}
|
|
65
|
+
{{#unless files.http}}
|
|
66
|
+
type FileStorage,
|
|
67
|
+
{{/unless}}
|
|
68
|
+
{{/if}}
|
|
58
69
|
type IntegrationEventPublisher,
|
|
59
70
|
{{#if broker.external}}
|
|
60
71
|
type IntegrationEventSubscriber,
|
|
@@ -86,6 +97,12 @@ import { relateSystemActors } from '{{alias.platform}}/auth/relate-system-actors
|
|
|
86
97
|
import { createCommandBus } from '{{alias.platform}}/buses/create-command-bus{{alias.ext}}';
|
|
87
98
|
import { createQueryBus } from '{{alias.platform}}/buses/create-query-bus{{alias.ext}}';
|
|
88
99
|
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
100
|
+
{{#if files.http}}
|
|
101
|
+
import { fileRoutes } from '{{alias.platform}}/files/file-routes{{alias.ext}}';
|
|
102
|
+
{{/if}}
|
|
103
|
+
{{#if files.any}}
|
|
104
|
+
import { filesModule } from '{{alias.platform}}/files/files.module{{alias.ext}}';
|
|
105
|
+
{{/if}}
|
|
89
106
|
import { layFoundations, type Foundations } from '{{alias.platform}}/lay-foundations{{alias.ext}}';
|
|
90
107
|
import { platformModule, type PlatformOptions } from '{{alias.platform}}/platform.module{{alias.ext}}';
|
|
91
108
|
// ddd-ts-kit:imports
|
|
@@ -94,6 +111,10 @@ import { platformModule, type PlatformOptions } from '{{alias.platform}}/platfor
|
|
|
94
111
|
export interface ApplicationOptions extends PlatformOptions {
|
|
95
112
|
/** Whether this process runs the scheduled jobs, and their settings; left out (the tools, the tests), no job runs by time. */
|
|
96
113
|
readonly jobs?: JobsOptions;
|
|
114
|
+
{{#if files.any}}
|
|
115
|
+
/** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
|
|
116
|
+
readonly files?: FileStorage;
|
|
117
|
+
{{/if}}
|
|
97
118
|
}
|
|
98
119
|
|
|
99
120
|
export interface Application {
|
|
@@ -102,6 +123,10 @@ export interface Application {
|
|
|
102
123
|
/** Authenticates every request and runs it inside the execution scope. */
|
|
103
124
|
readonly boundary: HttpBoundary;
|
|
104
125
|
{{/if}}
|
|
126
|
+
{{#if files.http}}
|
|
127
|
+
/** The routes that answer the signed links of a storage the application serves itself; mounted before any body parser. */
|
|
128
|
+
readonly fileRoutes: readonly Route[];
|
|
129
|
+
{{/if}}
|
|
105
130
|
{{#unless http.any}}
|
|
106
131
|
readonly routes: readonly never[];
|
|
107
132
|
{{/unless}}
|
|
@@ -170,6 +195,9 @@ export function composeApplication(
|
|
|
170
195
|
guard,
|
|
171
196
|
{{#if audit.on}}
|
|
172
197
|
auditModule(foundations.audit),
|
|
198
|
+
{{/if}}
|
|
199
|
+
{{#if files.any}}
|
|
200
|
+
filesModule(options.files ?? new InMemoryFileStorage()),
|
|
173
201
|
{{/if}}
|
|
174
202
|
...contexts.modules,
|
|
175
203
|
],
|
|
@@ -254,6 +282,9 @@ function running(container: Container, options: ApplicationOptions, contexts: Co
|
|
|
254
282
|
{{#unless http.any}}
|
|
255
283
|
routes: [],
|
|
256
284
|
{{/unless}}
|
|
285
|
+
{{#if files.http}}
|
|
286
|
+
fileRoutes: fileRoutes(container.resolve(FileStorage)),
|
|
287
|
+
{{/if}}
|
|
257
288
|
// What the outbox relay delivers with: each publication continues the trace stored with its event.
|
|
258
289
|
eventBus: tracedPublisher(container.resolve(EventBus)),
|
|
259
290
|
{{#if broker.external}}
|
|
@@ -5,6 +5,9 @@ import type { LogLevel, RateLimit } from '@ddd-ts-kit/kernel';
|
|
|
5
5
|
import type { LogLevel } from '@ddd-ts-kit/kernel';
|
|
6
6
|
{{/unless}}
|
|
7
7
|
import type { ResilienceSettings } from '{{alias.platform}}/resilience/resilience-settings{{alias.ext}}';
|
|
8
|
+
{{#if files.any}}
|
|
9
|
+
import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
|
|
10
|
+
{{/if}}
|
|
8
11
|
import type { TracingConfig } from '{{alias.platform}}/config/read-tracing{{alias.ext}}';
|
|
9
12
|
|
|
10
13
|
/** The validated configuration of the process: `loadConfig` is the only reader of the environment. */
|
|
@@ -49,6 +52,10 @@ export interface AppConfig {
|
|
|
49
52
|
/** Where unexpected failures are reported: a Sentry or a GlitchTip project. Without a DSN nothing is reported. */
|
|
50
53
|
readonly errorReporting: ErrorReportingConfig;
|
|
51
54
|
{{/if}}
|
|
55
|
+
{{#if files.any}}
|
|
56
|
+
/** Where the content of files lives (`files/open-files.ts`), never in the database. */
|
|
57
|
+
readonly files: FilesConfig;
|
|
58
|
+
{{/if}}
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
/** `LOG_LEVEL`, `LOG_FORMAT` and `LOG_SCRUB_MESSAGES`. */
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { LOG_LEVELS, type LogLevel } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
|
|
3
3
|
import { ConfigError } from '{{alias.platform}}/config/config-error{{alias.ext}}';
|
|
4
|
+
{{#if files.any}}
|
|
5
|
+
import { readFiles } from '{{alias.platform}}/config/read-files{{alias.ext}}';
|
|
6
|
+
{{/if}}
|
|
4
7
|
import { readTracing } from '{{alias.platform}}/config/read-tracing{{alias.ext}}';
|
|
5
8
|
|
|
6
9
|
const environments = ['development', 'test', 'production'] as const;
|
|
@@ -65,6 +68,12 @@ export function loadConfig(env: Variables): AppConfig {
|
|
|
65
68
|
{{#if errors.sentry}}
|
|
66
69
|
errorReporting: readErrorReporting(env, environment, problems),
|
|
67
70
|
{{/if}}
|
|
71
|
+
{{#if files.local}}
|
|
72
|
+
files: readFiles(env, environment, problems),
|
|
73
|
+
{{/if}}
|
|
74
|
+
{{#if files.s3}}
|
|
75
|
+
files: readFiles(env, problems),
|
|
76
|
+
{{/if}}
|
|
68
77
|
};
|
|
69
78
|
|
|
70
79
|
if (problems.length > 0) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type Variables = Readonly<Record<string, string | undefined>>;
|
|
2
|
+
|
|
3
|
+
/** Where the local storage keeps the content of files, and how a client reaches its signed links. */
|
|
4
|
+
export interface FilesConfig {
|
|
5
|
+
/** `FILES_DIRECTORY`: a directory out of version control. Default `.data/files`. */
|
|
6
|
+
readonly directory: string;
|
|
7
|
+
/** `FILES_PUBLIC_URL`: where the routes that answer the signed links are reached. Required in production; elsewhere `http://localhost:<PORT>/files` by default. */
|
|
8
|
+
readonly publicUrl: string;
|
|
9
|
+
/** `FILES_SIGNING_SECRET`: signs the links, 32 characters at least. Required in production; left out elsewhere, one is drawn at each start. */
|
|
10
|
+
readonly signingSecret?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The settings of the local file storage; a problem is reported by variable name only, never by value. */
|
|
14
|
+
export function readFiles(env: Variables, environment: string, problems: string[]): FilesConfig {
|
|
15
|
+
const production = environment === 'production';
|
|
16
|
+
const signingSecret = (env['FILES_SIGNING_SECRET'] ?? '').trim();
|
|
17
|
+
|
|
18
|
+
if (signingSecret.length < 32 && (signingSecret !== '' || production)) {
|
|
19
|
+
problems.push('FILES_SIGNING_SECRET must hold 32 characters at least, and is required in production');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
directory: env['FILES_DIRECTORY'] ?? '.data/files',
|
|
24
|
+
publicUrl: publicUrlOf(env, production, problems),
|
|
25
|
+
...(signingSecret === '' ? {} : { signingSecret }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Left to its default in production, every signed link would point at localhost. */
|
|
30
|
+
function publicUrlOf(env: Variables, production: boolean, problems: string[]): string {
|
|
31
|
+
const given = env['FILES_PUBLIC_URL'];
|
|
32
|
+
const publicUrl = given ?? `http://localhost:${env['PORT'] ?? '3000'}/files`;
|
|
33
|
+
|
|
34
|
+
if (!URL.canParse(publicUrl) || (production && given === undefined)) {
|
|
35
|
+
problems.push('FILES_PUBLIC_URL must be a URL, and is required in production');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return publicUrl;
|
|
39
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
type Variables = Readonly<Record<string, string | undefined>>;
|
|
2
|
+
|
|
3
|
+
/** The bucket that holds the content of files, on any provider of the S3 protocol. */
|
|
4
|
+
export interface FilesConfig {
|
|
5
|
+
/** `S3_ENDPOINT`: empty for AWS; MinIO of the compose stack `http://localhost:9000`; OVHcloud, Scaleway or R2 their own. */
|
|
6
|
+
readonly endpoint?: string;
|
|
7
|
+
/** `S3_REGION`: `us-east-1` by default, `auto` for Cloudflare R2. */
|
|
8
|
+
readonly region: string;
|
|
9
|
+
/** `S3_BUCKET`: created by the infrastructure code of the deployment, by the compose stack in development. */
|
|
10
|
+
readonly bucket: string;
|
|
11
|
+
/** `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY`: an access key allowed on this bucket only. */
|
|
12
|
+
readonly accessKeyId: string;
|
|
13
|
+
readonly secretAccessKey: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The settings of the S3 file storage; a problem is reported by variable name only, never by value. */
|
|
17
|
+
export function readFiles(env: Variables, problems: string[]): FilesConfig {
|
|
18
|
+
const endpoint = (env['S3_ENDPOINT'] ?? '').trim();
|
|
19
|
+
const region = (env['S3_REGION'] ?? '').trim();
|
|
20
|
+
|
|
21
|
+
if (endpoint !== '' && !URL.canParse(endpoint)) {
|
|
22
|
+
problems.push('S3_ENDPOINT must be a URL, or empty for AWS');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
...(endpoint === '' ? {} : { endpoint }),
|
|
27
|
+
region: region === '' ? 'us-east-1' : region,
|
|
28
|
+
bucket: requiredText(env, 'S3_BUCKET', problems),
|
|
29
|
+
accessKeyId: requiredText(env, 'S3_ACCESS_KEY_ID', problems),
|
|
30
|
+
secretAccessKey: requiredText(env, 'S3_SECRET_ACCESS_KEY', problems),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function requiredText(env: Variables, name: string, problems: string[]): string {
|
|
35
|
+
const value = (env[name] ?? '').trim();
|
|
36
|
+
|
|
37
|
+
if (value === '') {
|
|
38
|
+
problems.push(name + ' must be set');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
InMemoryCache,
|
|
9
9
|
InMemoryCommandBus,
|
|
10
10
|
InMemoryDomainEventDispatcher,
|
|
11
|
+
{{#if files.any}}
|
|
12
|
+
InMemoryFileStorage,
|
|
13
|
+
{{/if}}
|
|
11
14
|
InMemoryLock,
|
|
12
15
|
InMemoryQueryBus,
|
|
13
16
|
{{#if cache.rateLimit}}
|
|
@@ -19,6 +22,9 @@ import {
|
|
|
19
22
|
UuidGenerator,
|
|
20
23
|
{{#if errors.sentry}}
|
|
21
24
|
errorReportingMiddleware,
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{#if files.any}}
|
|
27
|
+
fileUploadsMiddleware,
|
|
22
28
|
{{/if}}
|
|
23
29
|
scopedPublisher,
|
|
24
30
|
dispatchingOnSave,
|
|
@@ -28,6 +34,9 @@ import {
|
|
|
28
34
|
type DomainEventDispatcher,
|
|
29
35
|
{{#if errors.sentry}}
|
|
30
36
|
type ErrorReporter,
|
|
37
|
+
{{/if}}
|
|
38
|
+
{{#if files.any}}
|
|
39
|
+
type FileStorage,
|
|
31
40
|
{{/if}}
|
|
32
41
|
type JobSettings,
|
|
33
42
|
} from '@ddd-ts-kit/kernel';
|
|
@@ -58,6 +67,9 @@ import { logDecisions } from '{{alias.platform}}/auth/log-decisions{{alias.ext}}
|
|
|
58
67
|
import { UseCaseProtection } from '{{alias.platform}}/auth/use-case-protection{{alias.ext}}';
|
|
59
68
|
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
60
69
|
import type { EventProvider } from '{{alias.platform}}/events/event-provider{{alias.ext}}';
|
|
70
|
+
{{#if files.any}}
|
|
71
|
+
import { createFiles, type Files } from '{{alias.platform}}/files/create-files{{alias.ext}}';
|
|
72
|
+
{{/if}}
|
|
61
73
|
import { ConfiguredJobScheduler } from '{{alias.platform}}/jobs/configured-job-scheduler{{alias.ext}}';
|
|
62
74
|
import { createLogger, type LogSettings } from '{{alias.platform}}/observability/create-logger{{alias.ext}}';
|
|
63
75
|
import { createMetrics } from '{{alias.platform}}/observability/create-metrics{{alias.ext}}';
|
|
@@ -96,6 +108,10 @@ export interface PlatformOptions {
|
|
|
96
108
|
/** The Redis protocol server; left out, the cache, the lock and the limiter stay in the memory of the process. */
|
|
97
109
|
readonly redis?: RedisServices;
|
|
98
110
|
{{/if}}
|
|
111
|
+
{{#if files.any}}
|
|
112
|
+
/** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
|
|
113
|
+
readonly files?: FileStorage;
|
|
114
|
+
{{/if}}
|
|
99
115
|
}
|
|
100
116
|
|
|
101
117
|
/** Replacing a provider (another broker, another clock) happens here and nowhere else. */
|
|
@@ -121,13 +137,19 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
|
|
|
121
137
|
const protection = new UseCaseProtection(authorizer, onDecision);
|
|
122
138
|
const adapter = adapterOf(options.resilience ?? defaultResilience, { traced, domainEvents });
|
|
123
139
|
const observed = observing(foundations, protection.guard, traced.useCase);
|
|
140
|
+
{{#if files.any}}
|
|
141
|
+
const files = filesOf(options, foundations);
|
|
142
|
+
{{/if}}
|
|
124
143
|
|
|
125
144
|
return {
|
|
126
145
|
...foundations,
|
|
127
146
|
...eventsOn(persistence, options, { scope, traced }),
|
|
128
|
-
// Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then runs in the unit of work.
|
|
147
|
+
// Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then {{#if files.any}}has the file it carries staged, out of any transaction, and {{/if}}runs in the unit of work.
|
|
129
148
|
commands: chain(new InMemoryCommandBus(), [
|
|
130
149
|
...observed,
|
|
150
|
+
{{#if files.any}}
|
|
151
|
+
fileUploadsMiddleware(() => files),
|
|
152
|
+
{{/if}}
|
|
131
153
|
...beforeTheTransaction(foundations, options),
|
|
132
154
|
unitOfWorkMiddleware(persistence.unitOfWork),
|
|
133
155
|
]),
|
|
@@ -139,9 +161,24 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
|
|
|
139
161
|
adapter,
|
|
140
162
|
selfGoverned: (instance, info) => adapter(ownPolicy()(instance, info), info),
|
|
141
163
|
protection,
|
|
164
|
+
{{#if files.any}}
|
|
165
|
+
files,
|
|
166
|
+
{{/if}}
|
|
142
167
|
};
|
|
143
168
|
}
|
|
144
169
|
|
|
170
|
+
{{#if files.any}}
|
|
171
|
+
/** Where the content of files lives: the storage of `main.ts`; left out (the tools, the tests), the memory of the process. */
|
|
172
|
+
function filesOf(options: PlatformOptions, foundations: Foundations): Files {
|
|
173
|
+
{{#if errors.none}}
|
|
174
|
+
return createFiles(options.files ?? new InMemoryFileStorage(), { ...foundations, errors: new NoopErrorReporter() });
|
|
175
|
+
{{/if}}
|
|
176
|
+
{{#if errors.sentry}}
|
|
177
|
+
return createFiles(options.files ?? new InMemoryFileStorage(), foundations);
|
|
178
|
+
{{/if}}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
{{/if}}
|
|
145
182
|
/** What surrounds every use case on both buses, outermost first, before what each bus adds. */
|
|
146
183
|
function observing(foundations: Foundations, guard: BusMiddleware, span: BusMiddleware): readonly BusMiddleware[] {
|
|
147
184
|
{{#if errors.none}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ModuleBuilder } from '@ddd-ts-kit/di';
|
|
2
|
+
import {
|
|
3
|
+
AcceptEveryFileScanner,
|
|
4
|
+
Clock,
|
|
5
|
+
ErrorReporter,
|
|
6
|
+
ExecutionScope,
|
|
7
|
+
FileKeys,
|
|
8
|
+
FileScanner,
|
|
9
|
+
FileStaging,
|
|
10
|
+
FileStorage,
|
|
11
|
+
IdGenerator,
|
|
12
|
+
TenantFileKeys,
|
|
13
|
+
} from '@ddd-ts-kit/kernel';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The ports of files on a storage: the keys generated on the server, under the tenant when there
|
|
17
|
+
* is one, the scanner a file passes before it is accepted, and the staging that keeps the storage
|
|
18
|
+
* consistent with the database. The application and the handler specs bind them alike.
|
|
19
|
+
*/
|
|
20
|
+
export function bindFiles(builder: ModuleBuilder, storage: FileStorage): void {
|
|
21
|
+
builder.bind(FileStorage).toValue(storage);
|
|
22
|
+
// TODO(platform): bind a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
|
|
23
|
+
builder.bind(FileScanner).toValue(new AcceptEveryFileScanner());
|
|
24
|
+
|
|
25
|
+
builder
|
|
26
|
+
.bind(FileKeys)
|
|
27
|
+
.toFactory((resolve) => new TenantFileKeys(resolve(IdGenerator), resolve(Clock), resolve(ExecutionScope)));
|
|
28
|
+
|
|
29
|
+
builder
|
|
30
|
+
.bind(FileStaging)
|
|
31
|
+
.toFactory((resolve) => new FileStaging(resolve(FileStorage), resolve(FileScanner), resolve(ErrorReporter)));
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AcceptEveryFileScanner,
|
|
3
|
+
FileStaging,
|
|
4
|
+
TenantFileKeys,
|
|
5
|
+
type Clock,
|
|
6
|
+
type ErrorReporter,
|
|
7
|
+
type ExecutionScope,
|
|
8
|
+
type FileKeys,
|
|
9
|
+
type FileStorage,
|
|
10
|
+
type IdGenerator,
|
|
11
|
+
} from '@ddd-ts-kit/kernel';
|
|
12
|
+
|
|
13
|
+
/** Where files live, the keys they are stored under and the staging that keeps them consistent with the database. */
|
|
14
|
+
export interface Files {
|
|
15
|
+
readonly storage: FileStorage;
|
|
16
|
+
readonly keys: FileKeys;
|
|
17
|
+
readonly staging: FileStaging;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What files are built on: the foundations of the platform. */
|
|
21
|
+
interface Grounds {
|
|
22
|
+
readonly clock: Clock;
|
|
23
|
+
readonly ids: IdGenerator;
|
|
24
|
+
readonly scope: ExecutionScope;
|
|
25
|
+
readonly errors: ErrorReporter;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Files as a capability of the platform: the keys generated on the server, under the tenant when there is one, and the staging. */
|
|
29
|
+
export function createFiles(storage: FileStorage, { clock, ids, scope, errors }: Grounds): Files {
|
|
30
|
+
// TODO(platform): give a scanner of your own (an antivirus, a content check) before accepting files from people you do not know.
|
|
31
|
+
const staging = new FileStaging(storage, new AcceptEveryFileScanner(), errors);
|
|
32
|
+
|
|
33
|
+
return { storage, keys: new TenantFileKeys(ids, clock, scope), staging };
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { signedFileRoutes, type Route } from '@ddd-ts-kit/http';
|
|
2
|
+
import { ServedFileStorage, type FileStorage } from '@ddd-ts-kit/kernel';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The routes that answer the signed links of a storage the application serves itself: the local
|
|
6
|
+
* directory, or the memory of the tests. None for an object store, which answers its own links.
|
|
7
|
+
*/
|
|
8
|
+
export function fileRoutes(storage: FileStorage): readonly Route[] {
|
|
9
|
+
return storage instanceof ServedFileStorage ? signedFileRoutes(storage) : [];
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineContextModule, type ContextModule } from '@ddd-ts-kit/di';
|
|
2
|
+
import { Clock, FileStaging, PurgeStagedFiles, type FileStorage } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { bindFiles } from '{{alias.platform}}/files/bind-files{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Files as a capability of the platform: the storage `main.ts` opened (the memory of the process
|
|
7
|
+
* for the tools and the tests), its ports, and the hourly purge of what rolled-back commands left
|
|
8
|
+
* in `staging/`.
|
|
9
|
+
*/
|
|
10
|
+
export function filesModule(storage: FileStorage): ContextModule {
|
|
11
|
+
return defineContextModule({
|
|
12
|
+
name: 'files',
|
|
13
|
+
register(builder) {
|
|
14
|
+
bindFiles(builder, storage);
|
|
15
|
+
builder.job('files.purge-staged', { every: '1h' }).handledBy(PurgeStagedFiles, [FileStaging, Clock]);
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LocalFileStorage, type FileStorage } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where the content of files lives: a directory of this machine, never the database. The
|
|
6
|
+
* application answers its signed links itself, under `/files`. One machine only: before running
|
|
7
|
+
* several instances, move to an object store (`ddd-ts-kit init --force --storage s3`).
|
|
8
|
+
*/
|
|
9
|
+
export function openFiles(config: FilesConfig): FileStorage {
|
|
10
|
+
const { directory, publicUrl, signingSecret } = config;
|
|
11
|
+
|
|
12
|
+
return new LocalFileStorage({ directory, baseUrl: publicUrl, ...(signingSecret === undefined ? {} : { secret: signingSecret }) });
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FileStorage } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { S3FileStorage, s3ClientOf } from '@ddd-ts-kit/s3';
|
|
3
|
+
import type { FilesConfig } from '{{alias.platform}}/config/read-files{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
/** Where the content of files lives: a bucket of the S3 protocol, MinIO in the compose stack, never the database. */
|
|
6
|
+
export function openFiles(config: FilesConfig): FileStorage {
|
|
7
|
+
const { bucket, ...settings } = config;
|
|
8
|
+
|
|
9
|
+
return new S3FileStorage({ client: s3ClientOf(settings), bucket });
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Resolve } from '@ddd-ts-kit/di';
|
|
2
|
+
import { FileKeys, FileStaging, fileUploadsMiddleware, type BusMiddleware } from '@ddd-ts-kit/kernel';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Stages the file a command carries (a `FileUpload`), after the permission and before the
|
|
6
|
+
* transaction, so that no transaction waits while a client uploads. Resolved at each command
|
|
7
|
+
* that carries a file: building the bus opens nothing.
|
|
8
|
+
*/
|
|
9
|
+
export function stagingUploads(resolve: Resolve): BusMiddleware {
|
|
10
|
+
return fileUploadsMiddleware(() => ({ keys: resolve(FileKeys), staging: resolve(FileStaging) }));
|
|
11
|
+
}
|
|
@@ -19,7 +19,7 @@ export interface HttpServer {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** What the server needs of the application: its routes and what stands at its edge. */
|
|
22
|
-
type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}>;
|
|
22
|
+
type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
|
|
23
23
|
|
|
24
24
|
export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
|
|
25
25
|
const app = express();
|
|
@@ -27,6 +27,10 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
|
|
|
27
27
|
app.disable('x-powered-by');
|
|
28
28
|
{{#if cache.rateLimit}}
|
|
29
29
|
guardTheDoor(app, served, config);
|
|
30
|
+
{{/if}}
|
|
31
|
+
{{#if files.http}}
|
|
32
|
+
// Before the JSON parser, which would read first a JSON file sent through a signed link.
|
|
33
|
+
mountExpress(app, served.fileRoutes, served.boundary);
|
|
30
34
|
{{/if}}
|
|
31
35
|
app.use(express.json());
|
|
32
36
|
{{#if docs.any}}
|
|
@@ -17,7 +17,7 @@ export interface HttpServer {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** What the server needs of the application: its routes and what stands at its edge. */
|
|
20
|
-
type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}>;
|
|
20
|
+
type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
|
|
21
21
|
|
|
22
22
|
export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
|
|
23
23
|
const app = Fastify();
|
|
@@ -25,6 +25,9 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
|
|
|
25
25
|
{{#if cache.rateLimit}}
|
|
26
26
|
guardTheDoor(app, served, config);
|
|
27
27
|
{{/if}}
|
|
28
|
+
{{#if files.http}}
|
|
29
|
+
mountFastify(app, served.fileRoutes, served.boundary);
|
|
30
|
+
{{/if}}
|
|
28
31
|
{{#if docs.any}}
|
|
29
32
|
mountFastify(app, withDocumentation(served.routes, config), served.boundary);
|
|
30
33
|
{{/if}}
|