5htp-core 0.2.9 → 0.3.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.
Files changed (75) hide show
  1. package/package.json +7 -5
  2. package/src/client/app/component.tsx +2 -2
  3. package/src/client/assets/css/text/titres.less +4 -0
  4. package/src/client/components/Dialog/card.tsx +1 -1
  5. package/src/client/components/Dialog/index.less +3 -3
  6. package/src/client/components/inputv3/date/index.tsx +1 -1
  7. package/src/client/components/inputv3/index.tsx +14 -4
  8. package/src/client/pages/_layout/index.tsx +3 -3
  9. package/src/client/pages/_messages/400.tsx +2 -2
  10. package/src/client/pages/_messages/401.tsx +2 -2
  11. package/src/client/pages/_messages/403.tsx +2 -2
  12. package/src/client/pages/_messages/404.tsx +2 -2
  13. package/src/client/pages/_messages/500.tsx +2 -2
  14. package/src/client/pages/useHeader.tsx +2 -1
  15. package/src/client/services/router/components/router.tsx +1 -1
  16. package/src/client/services/router/index.tsx +5 -1
  17. package/src/client/services/router/response/index.tsx +5 -2
  18. package/src/common/data/objets.ts +0 -25
  19. package/src/common/router/index.ts +8 -12
  20. package/src/common/router/layouts.ts +3 -1
  21. package/src/common/router/register.ts +5 -3
  22. package/src/common/router/response/index.ts +3 -3
  23. package/src/server/app/commands.ts +2 -11
  24. package/src/server/app/{config.ts → container/config.ts} +4 -1
  25. package/src/server/app/container/index.ts +84 -0
  26. package/src/server/app/index.ts +73 -136
  27. package/src/server/app/instance.ts +3 -0
  28. package/src/server/app/service/container.ts +136 -0
  29. package/src/server/app/service/index.ts +219 -0
  30. package/src/server/index.ts +9 -3
  31. package/src/server/services/cache/index.ts +42 -16
  32. package/src/server/services/cache/service.json +6 -0
  33. package/src/server/services/console/index.ts +35 -22
  34. package/src/server/services/console/service.json +6 -0
  35. package/src/server/services/cron/index.ts +11 -11
  36. package/src/server/services/cron/service.json +6 -0
  37. package/src/server/services/database/connection.ts +26 -34
  38. package/src/server/services/database/index.ts +41 -21
  39. package/src/server/services/database/metas.ts +12 -7
  40. package/src/server/services/database/repository.ts +0 -9
  41. package/src/server/services/database/service.json +6 -0
  42. package/src/server/services/database/stats.ts +3 -3
  43. package/src/server/services/disks/driver.ts +9 -7
  44. package/src/server/services/disks/drivers/local/index.ts +199 -0
  45. package/src/server/services/disks/drivers/local/service.json +6 -0
  46. package/src/server/services/disks/drivers/s3/index.ts +282 -0
  47. package/src/server/services/disks/drivers/s3/service.json +6 -0
  48. package/src/server/services/disks/index.ts +47 -16
  49. package/src/server/services/disks/service.json +6 -0
  50. package/src/server/services/email/index.ts +16 -4
  51. package/src/server/services/email/service.json +6 -0
  52. package/src/server/services/fetch/index.ts +52 -8
  53. package/src/server/services/fetch/service.json +6 -0
  54. package/src/server/services/router/http/index.ts +12 -9
  55. package/src/server/services/router/index.ts +95 -68
  56. package/src/server/services/router/request/api.ts +1 -1
  57. package/src/server/services/router/response/index.ts +13 -19
  58. package/src/server/services/router/service.json +6 -0
  59. package/src/server/services/router/service.ts +16 -29
  60. package/src/server/services/schema/{router.ts → router/index.ts} +19 -7
  61. package/src/server/services/schema/router/service.json +6 -0
  62. package/src/server/services/schema/service.json +6 -0
  63. package/src/server/services/security/encrypt/{aes.ts → aes/index.ts} +16 -3
  64. package/src/server/services/security/encrypt/aes/service.json +6 -0
  65. package/src/server/services/socket/index.ts +39 -13
  66. package/src/server/services/socket/service.json +6 -0
  67. package/src/server/services/users/index.ts +16 -4
  68. package/src/server/services/users/old.ts +1 -1
  69. package/src/server/services/users/router/index.ts +21 -14
  70. package/src/server/services/users/router/service.json +6 -0
  71. package/src/server/services/users/service.json +6 -0
  72. package/src/types/aliases.d.ts +5 -0
  73. package/tsconfig.common.json +2 -0
  74. package/src/server/app/service.ts +0 -109
  75. /package/src/server/{patch.ts → app/container/patch.ts} +0 -0
@@ -7,7 +7,8 @@
7
7
  */
8
8
 
9
9
  // Core
10
- import Application, { Service } from '@server/app';
10
+ import type { Application } from '@server/app';
11
+ import Service from '@server/app/service';
11
12
  import markdown from '@common/data/markdown';
12
13
 
13
14
  // Speciic
@@ -108,14 +109,25 @@ export default class Email extends Service<Config, Hooks, Application> {
108
109
 
109
110
  private transporters = this.config.transporters;
110
111
 
111
- public async register() {
112
-
113
- }
112
+ /*----------------------------------
113
+ - LIFECYCLE
114
+ ----------------------------------*/
114
115
 
115
116
  public async start() {
116
117
 
117
118
  }
118
119
 
120
+ public async ready() {
121
+
122
+ }
123
+
124
+ public async shutdown() {
125
+
126
+ }
127
+
128
+ /*----------------------------------
129
+ - ACTIONS
130
+ ----------------------------------*/
119
131
 
120
132
  public async send( to: string, subject: string, markdown: string, options?: TOptions );
121
133
  public async send( emails: TEmail | TEmail[], options?: TOptions ): Promise<void>;
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "Core/Email",
3
+ "name": "Email",
4
+ "parent": "app",
5
+ "dependences": []
6
+ }
@@ -10,21 +10,28 @@ import fs from 'fs-extra';
10
10
  import request from 'request';
11
11
 
12
12
  // Core: general
13
- import type Application from '@server/app';
14
- import Service from '@server/app/service';
13
+ import type { Application } from '@server/app';
14
+ import Service, { AnyService } from '@server/app/service';
15
+ import type DisksManager from '../disks';
16
+ import type FsDriver from '../disks/driver';
15
17
 
16
18
  /*----------------------------------
17
19
  - SERVICE TYPES
18
20
  ----------------------------------*/
19
21
 
20
22
  export type Config = {
21
-
23
+ debug?: boolean,
24
+ disk?: string
22
25
  }
23
26
 
24
27
  export type Hooks = {
25
28
 
26
29
  }
27
30
 
31
+ export type Services = {
32
+ disks: DisksManager
33
+ }
34
+
28
35
  /*----------------------------------
29
36
  - TYPES
30
37
  ----------------------------------*/
@@ -46,16 +53,47 @@ const LogPrefix = `[services][fetch]`
46
53
  - SERVICE
47
54
  - Tools that helps to consume external resources (including apis, ..)
48
55
  -----------------------------------*/
49
- export default class FetchService extends Service<Config, Hooks, Application> {
56
+ export default class FetchService extends Service<Config, Hooks, Application, Services> {
57
+
58
+ private disk?: FsDriver;
59
+
60
+ public constructor(
61
+ parent: AnyService,
62
+ config: Config,
63
+ services: Services,
64
+ app: Application
65
+ ) {
50
66
 
51
- public async register() {
67
+ super(parent, config, services, app);
68
+
69
+ if (this.services.disks)
70
+ this.disk = this.services.disks.get( config.disk );
52
71
 
53
72
  }
54
73
 
74
+ /*----------------------------------
75
+ - LIFECYCLE
76
+ ----------------------------------*/
77
+
55
78
  public async start() {
79
+
80
+
81
+
56
82
 
57
83
  }
58
84
 
85
+ public async ready() {
86
+
87
+ }
88
+
89
+ public async shutdown() {
90
+
91
+ }
92
+
93
+ /*----------------------------------
94
+ - ACTIONS
95
+ ----------------------------------*/
96
+
59
97
  public toBuffer( uri: string ): Promise<Buffer> {
60
98
  return new Promise<Buffer>((resolve, reject) => {
61
99
  request(uri, { encoding: null }, (err, res, body) => {
@@ -74,9 +112,15 @@ export default class FetchService extends Service<Config, Hooks, Application> {
74
112
  public async image(
75
113
  imageFileUrl: string,
76
114
  { width, height, fit, quality }: TImageConfig,
77
- saveToPath?: string
115
+ saveToBucket: string,
116
+ saveToPath?: string,
117
+ disk?: FsDriver
78
118
  ): Promise<Buffer | null> {
79
119
 
120
+ // Define target disk
121
+ if (this.disk === undefined)
122
+ throw new Error(`Please provide a Disks service in order to download files.`);
123
+
80
124
  // Download
81
125
  let imageBuffer: Buffer;
82
126
  try {
@@ -89,7 +133,7 @@ export default class FetchService extends Service<Config, Hooks, Application> {
89
133
  // Resize
90
134
  const processing = sharp( imageBuffer )
91
135
  // Max dimensions (save space)
92
- .resize(width, height, { fit })
136
+ .resize(width, height, { fit })
93
137
 
94
138
  // Convert to webp and finalize
95
139
  const processedBuffer = await processing.webp({ quality }).toBuffer().catch(e => {
@@ -100,7 +144,7 @@ export default class FetchService extends Service<Config, Hooks, Application> {
100
144
  // Save file
101
145
  if (saveToPath !== undefined && processedBuffer !== null) {
102
146
  console.log(LogPrefix, `Saving ${imageFileUrl} logo to ${saveToPath}`);
103
- fs.outputFileSync(saveToPath, processedBuffer);
147
+ await this.disk.outputFile(saveToBucket, saveToPath, processedBuffer);
104
148
  }
105
149
 
106
150
  // We return the original, because Vibrant.js doesn't support webp
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "Core/Fetch",
3
+ "name": "Fetch",
4
+ "parent": "app",
5
+ "dependences": []
6
+ }
@@ -22,7 +22,9 @@ import cookieParser from 'cookie-parser';
22
22
  import * as csp from 'express-csp-header';
23
23
 
24
24
  // Core
25
- import Application, { Service } from '@server/app';
25
+ import type { Application } from '@server/app';
26
+ import Container from '@server/app/container';
27
+ import Service from '@server/app/service';
26
28
  import type Router from '..';
27
29
 
28
30
  // Middlewaees (core)
@@ -34,6 +36,8 @@ import { MiddlewareFormData } from './multipart';
34
36
 
35
37
  export type Config = {
36
38
 
39
+ debug?: boolean,
40
+
37
41
  // Access
38
42
  domain: string,
39
43
  port: number,
@@ -58,16 +62,18 @@ export type Hooks = {
58
62
  /*----------------------------------
59
63
  - FUNCTION
60
64
  ----------------------------------*/
61
- export default class HttpServer extends Service<Config, Hooks, Application> {
65
+ export default class HttpServer {
62
66
 
63
67
  public http: http.Server | https.Server;
64
68
  public express: express.Express;
65
69
 
66
70
  public publicUrl: string;
67
71
 
68
- public constructor( config: Config, public router: Router ) {
69
-
70
- super( router.app, config );
72
+ public constructor(
73
+ public config: Config,
74
+ public router: Router,
75
+ public app = router.app
76
+ ) {
71
77
 
72
78
  // Init
73
79
  this.publicUrl = this.app.env.name === 'local'
@@ -85,9 +91,6 @@ export default class HttpServer extends Service<Config, Hooks, Application> {
85
91
  /*----------------------------------
86
92
  - HOOKS
87
93
  ----------------------------------*/
88
- public async register() {
89
-
90
- }
91
94
 
92
95
  public async start() {
93
96
 
@@ -113,7 +116,7 @@ export default class HttpServer extends Service<Config, Hooks, Application> {
113
116
  routes.use('/public', cors());
114
117
  routes.use(
115
118
  '/public',
116
- expressStaticGzip( this.app.path.root + '/bin/public', {
119
+ expressStaticGzip( Container.path.root + '/bin/public', {
117
120
  enableBrotli: true,
118
121
  serveStatic: {
119
122
  setHeaders: function setCustomCacheControl(res, path) {
@@ -10,18 +10,17 @@
10
10
  ----------------------------------*/
11
11
 
12
12
  // Node
13
- import path from 'path';
14
-
15
13
  // Npm
16
14
  import type express from 'express';
17
15
  import { v4 as uuid } from 'uuid';
18
- import fs from 'fs-extra';
19
16
  import type { GlobImportedWithMetas } from 'babel-plugin-glob-import';
20
17
 
21
18
  // Core
22
- import Application, { Service } from '@server/app';
19
+ import type { Application } from '@server/app';
20
+ import Service, { AnyService } from '@server/app/service';
21
+ import type { TRegisteredServicesIndex } from '@server/app/service/container';
23
22
  import context from '@server/context';
24
- import type DiskDriver from '@server/services/disks/driver';
23
+ import type DisksManager from '@server/services/disks';
25
24
  import { CoreError, NotFound } from '@common/errors';
26
25
  import BaseRouter, {
27
26
  TRoute, TErrorRoute, TRouteModule,
@@ -29,14 +28,14 @@ import BaseRouter, {
29
28
  } from '@common/router';
30
29
  import { buildRegex, getRegisterPageArgs } from '@common/router/register';
31
30
  import { layoutsList, getLayout } from '@common/router/layouts';
32
- import { TFetcherList, TFetcher } from '@common/router/request/api';
31
+ import { TFetcherList } from '@common/router/request/api';
33
32
  import type { TFrontRenderer } from '@common/router/response/page';
34
33
  import type { TSsrUnresolvedRoute, TRegisterPageArgs } from '@client/services/router';
35
34
 
36
35
  // Specific
37
36
  import RouterService from './service';
38
37
  import ServerRequest from "./request";
39
- import ServerResponse, { TRouterContext } from './response';
38
+ import ServerResponse, { TRouterContext, TRouterContextServices } from './response';
40
39
  import Page from './response/page';
41
40
  import HTTP, { Config as HttpServiceConfig } from './http';
42
41
  import DocumentRenderer from './response/page/document';
@@ -49,7 +48,7 @@ export { default as RouterService } from './service';
49
48
  export { default as RequestService } from './request/service';
50
49
  export type { default as Request, UploadedFile } from "./request";
51
50
  export type { default as Response, TRouterContext } from "./response";
52
- export type { TRoute } from '@common/router';
51
+ export type { TRoute, TAnyRoute } from '@common/router';
53
52
 
54
53
  export type TApiRegisterArgs<TRouter extends ServerRouter> = ([
55
54
  path: string,
@@ -78,10 +77,6 @@ export type HttpHeaders = { [cle: string]: string }
78
77
 
79
78
  const LogPrefix = '[router]';
80
79
 
81
- export type TRouterServicesList = {
82
- [serviceName: string]: RouterService<ServerRouter>
83
- }
84
-
85
80
  export type Config<
86
81
  TServiceList extends TRouterServicesList = TRouterServicesList,
87
82
  TAdditionnalSsrData extends {} = {}
@@ -89,24 +84,23 @@ export type Config<
89
84
 
90
85
  debug: boolean,
91
86
 
92
- disk: DiskDriver,
87
+ disk?: string, // Disk driver ID
93
88
 
94
89
  http: HttpServiceConfig
95
90
 
96
- // Set it as a function, so when we instanciate the services, we can callthis.router to pass the router instance in roiuter services
97
- services: TServiceList,
91
+ context: (
92
+ request: ServerRequest<ServerRouter>,
93
+ app: Application
94
+ ) => TAdditionnalSsrData,
95
+ }
98
96
 
99
- context: (request: ServerRequest<ServerRouter>) => TAdditionnalSsrData,
97
+ export type Services = {
98
+ disks?: DisksManager
99
+ } & TRegisteredServicesIndex< RouterService<ServerRouter> >
100
100
 
101
- // Protections against bots
102
- // TODO: move to Protection service
103
- /*security: {
104
- recaptcha: {
105
- prv: string,
106
- pub: string
107
- },
108
- iphub: string
109
- },*/
101
+ // Set it as a function, so when we instanciate the services, we can callthis.router to pass the router instance in roiuter services
102
+ type TRouterServicesList = {
103
+ [serviceName: string]: RouterService<ServerRouter>
110
104
  }
111
105
 
112
106
  export type Hooks = {
@@ -119,12 +113,12 @@ export type Hooks = {
119
113
  export default class ServerRouter<
120
114
  TConfig extends Config = Config,
121
115
  TApplication extends Application = Application
122
- > extends Service<TConfig, Hooks, TApplication> implements BaseRouter {
116
+ > extends Service<TConfig, Hooks, TApplication, Services> implements BaseRouter {
123
117
 
124
118
  // Services
125
119
  public http: HTTP;
126
- public services: TConfig["services"];
127
- public render: DocumentRenderer;
120
+ public render: DocumentRenderer<this>;
121
+ protected routerServices: {[serviceId: string]: RouterService} = {}
128
122
 
129
123
  // Indexed
130
124
  public routes: TRoute[] = []; // API + pages front front
@@ -135,44 +129,59 @@ export default class ServerRouter<
135
129
  - SERVICE
136
130
  ----------------------------------*/
137
131
 
138
- public constructor(app: TApplication, config: TConfig) {
132
+ public constructor(
133
+ parent: AnyService,
134
+ config: TConfig,
135
+ services: TRegisteredServicesIndex<RouterService>,
136
+ app: TApplication,
137
+ ) {
139
138
 
140
- super(app, config);
139
+ super(parent, config, services, app);
141
140
 
142
141
  this.http = new HTTP(config.http, this);
143
142
  this.render = new DocumentRenderer(this);
144
- this.services = config.services;
145
143
 
146
144
  }
147
145
 
148
- public async register() {
149
-
150
- // Since route registering requires all services to be ready,
151
- // We load routes only when all services are ready
152
- this.app.on('ready', async () => {
153
- // Use require to avoid circular references
154
- this.registerRoutes([
155
- ...require("metas:@/server/routes/**/*.ts"),
156
- ...require("metas:@/client/pages/**/*.tsx"),
157
- ...require("metas:@client/pages/**/*.tsx")
158
- ]);
159
- })
146
+ /*----------------------------------
147
+ - LIFECYCLE
148
+ ----------------------------------*/
149
+
150
+ protected async start() {
151
+
152
+ // Detect router services
153
+ for (const serviceName in this.services) {
154
+
155
+ const routerService = this.services[serviceName];
156
+ if (routerService instanceof RouterService)
157
+ this.routerServices[ serviceName ] = routerService;
158
+ }
159
+
160
+ console.log("this.routerServices", Object.keys( this.routerServices ));
160
161
  }
161
162
 
162
- public async start() {
163
- this.startServices();
163
+ public async ready() {
164
+
165
+ // Use require to avoid circular references
166
+ this.registerRoutes([
167
+ ...require("metas:@/server/routes/**/*.ts"),
168
+ ...require("metas:@/client/pages/**/*.tsx"),
169
+ ...require("metas:@client/pages/**/*.tsx")
170
+ ]);
171
+
172
+ // Start HTTP server
173
+ await this.http.start();
174
+
164
175
  }
165
176
 
166
- private async startServices() {
167
- console.log(LogPrefix, `Starting router services`);
177
+ public async shutdown() {
168
178
 
169
- for (const serviceId in this.services) {
170
- const service = this.services[serviceId];
171
- service.attach(this);
172
- await service.register();
173
- }
174
179
  }
175
180
 
181
+ /*----------------------------------
182
+ - ACTIONS
183
+ ----------------------------------*/
184
+
176
185
  private registerRoutes(defModules: GlobImportedWithMetas<TRouteModule>) {
177
186
 
178
187
  for (const routeModule of defModules) {
@@ -181,8 +190,14 @@ export default class ServerRouter<
181
190
  if (!register)
182
191
  continue;
183
192
 
184
- console.log(LogPrefix, `Register file:`, routeModule.matches.join('/'));
185
- register(this.app);
193
+ this.config.debug && console.log(LogPrefix, `Register file:`, routeModule.matches.join('/'));
194
+ try {
195
+ register(this.app.services);
196
+ } catch (error) {
197
+ console.error("Failed to register route file:", routeModule);
198
+ console.error('Register function:', register.toString());
199
+ throw error;
200
+ }
186
201
  }
187
202
 
188
203
  this.afterRegister();
@@ -281,15 +296,12 @@ export default class ServerRouter<
281
296
 
282
297
  private async afterRegister() {
283
298
 
284
- console.info("Pre-Loading request services");
285
- //await TrackingService.LoadCache();
286
-
287
299
  // Generate typescript typings
288
300
  if (this.app.env.profile === 'dev')
289
301
  this.genTypings();
290
302
 
291
303
  // Ordonne par ordre de priorité
292
- console.info("Loading routes ...");
304
+ this.config.debug && console.info("Loading routes ...");
293
305
  this.routes.sort((r1, r2) => {
294
306
 
295
307
  const prioDelta = r2.options.priority - r1.options.priority;
@@ -304,12 +316,12 @@ export default class ServerRouter<
304
316
  return 0;
305
317
  })
306
318
  // - Génère les définitions de route pour le client
307
- console.info(`Registered routes:`);
319
+ this.config.debug && console.info(`Registered routes:`);
308
320
  for (const route of this.routes) {
309
321
 
310
322
  const chunkId = route.options["id"];
311
323
 
312
- console.info('-',
324
+ this.config.debug && console.info('-',
313
325
  route.method,
314
326
  route.path,
315
327
  ' :: ', JSON.stringify(route.options)
@@ -324,13 +336,13 @@ export default class ServerRouter<
324
336
 
325
337
  }
326
338
 
327
- console.info(`Registered error pages:`);
339
+ this.config.debug && console.info(`Registered error pages:`);
328
340
  for (const code in this.errors) {
329
341
 
330
342
  const route = this.errors[code];
331
343
  const chunkId = route.options["id"];
332
344
 
333
- console.info('-', code,
345
+ this.config.debug && console.info('-', code,
334
346
  ' :: ', JSON.stringify(route.options)
335
347
  );
336
348
 
@@ -340,19 +352,19 @@ export default class ServerRouter<
340
352
  });
341
353
  }
342
354
 
343
- console.info(`Registered layouts:`);
355
+ this.config.debug && console.info(`Registered layouts:`);
344
356
  for (const layoutId in layoutsList) {
345
357
 
346
358
  const layout = layoutsList[layoutId];
347
359
 
348
- console.info('-', layoutId, layout);
360
+ this.config.debug && console.info('-', layoutId, layout);
349
361
  }
350
362
 
351
- console.info(this.routes.length + " routes where registered.");
363
+ this.config.debug && console.info(this.routes.length + " routes where registered.");
352
364
  }
353
365
 
354
366
  private genTypings() {
355
- fs.outputFileSync( path.join(this.app.path.typings, 'routes.d.ts'), `
367
+ /*fs.outputFileSync( path.join(this.app.path.typings, 'routes.d.ts'), `
356
368
  declare type Routes = {
357
369
  ${this.routes.map( route => `
358
370
  '${route.path}': {
@@ -363,7 +375,7 @@ declare type Routes = {
363
375
  `).join(',')}
364
376
  }
365
377
  }
366
- `);
378
+ `);*/
367
379
  }
368
380
 
369
381
  /*----------------------------------
@@ -469,6 +481,21 @@ declare type Routes = {
469
481
  });
470
482
  }
471
483
 
484
+ public createContextServices( request: ServerRequest<this> ) {
485
+
486
+ const contextServices: Partial<TRouterContextServices<this>> = {}
487
+ for (const serviceName in this.routerServices) {
488
+
489
+ const routerService = this.routerServices[serviceName];
490
+ const requestService = routerService.requestService( request );
491
+ if (requestService !== null)
492
+ contextServices[ serviceName ] = requestService;
493
+
494
+ }
495
+
496
+ return contextServices;
497
+ }
498
+
472
499
  public async resolve(request: ServerRequest<this>): Promise<ServerResponse<this>> {
473
500
 
474
501
  console.info(LogPrefix, request.ip, request.method, request.domain, request.path);
@@ -541,7 +568,7 @@ declare type Routes = {
541
568
  request.res.json(responseData);
542
569
  }
543
570
 
544
- private async handleError(e: CoreError, request: ServerRequest<ServerRouter>) {
571
+ private async handleError( e: CoreError, request: ServerRequest<ServerRouter> ) {
545
572
 
546
573
  const code = 'http' in e ? e.http : 500;
547
574
  const route = this.errors[code];
@@ -20,7 +20,7 @@ import ApiClientService, {
20
20
  ----------------------------------*/
21
21
  export default class ApiClientRequest extends RequestService implements ApiClientService {
22
22
 
23
- public async start() {
23
+ protected async start() {
24
24
 
25
25
  }
26
26
 
@@ -11,11 +11,11 @@
11
11
  import express from 'express';
12
12
 
13
13
  // Core
14
- import Application from '@server/app';
14
+ import { Application } from '@server/app';
15
15
  import type ServerRouter from '@server/services/router';
16
16
  import ServerRequest from '@server/services/router/request';
17
- import { TRoute } from '@common/router';
18
- import { NotFound, Forbidden } from '@common/errors';
17
+ import { TRoute, TAnyRoute } from '@common/router';
18
+ import { NotFound, Forbidden, Anomaly } from '@common/errors';
19
19
  import BaseResponse, { TResponseData } from '@common/router/response';
20
20
  import Page from './page';
21
21
 
@@ -50,8 +50,6 @@ export type TRouterContext<TRouter extends ServerRouter = ServerRouter> = (
50
50
  TRouterContextServices<TRouter>
51
51
  )
52
52
 
53
- type TRouterContextWithPage = With<TRouterContext, 'page'>
54
-
55
53
  export type TRouterContextServices<TRouter extends ServerRouter> = (
56
54
  // Custom context via servuces
57
55
  // For each roiuter service, return the request service (returned by roiuterService.requestService() )
@@ -92,7 +90,7 @@ export default class ServerResponse<
92
90
  this.app = this.router.app;
93
91
  }
94
92
 
95
- public async runController( route: TRoute, additionnalData: {} = {} ) {
93
+ public async runController( route: TAnyRoute, additionnalData: {} = {} ) {
96
94
 
97
95
  this.route = route;
98
96
 
@@ -128,17 +126,9 @@ export default class ServerResponse<
128
126
  private async createContext( route: TRoute ): Promise<TRequestContext> {
129
127
 
130
128
 
131
- const contextServices: Partial<TRouterContextServices<TRouter>> = {}
132
- for (const serviceName in this.router.services) {
133
-
134
- const routerService = this.router.services[serviceName];
135
- const requestService = routerService.requestService( this.request );
136
- if (requestService !== null)
137
- contextServices[ serviceName ] = requestService;
138
-
139
- }
129
+ const contextServices = this.router.createContextServices(this.request);
140
130
 
141
- const customSsrData = this.router.config.context(this.request);
131
+ const customSsrData = this.router.config.context(this.request, this.app);
142
132
 
143
133
  const context: TRequestContext = {
144
134
  // Router context
@@ -160,7 +150,7 @@ export default class ServerResponse<
160
150
 
161
151
  public forSsr( page: Page<TRouter> ): TBasicSSrData {
162
152
 
163
- const customSsrData = this.router.config.context(this.request);
153
+ const customSsrData = this.router.config.context(this.request, this.app);
164
154
 
165
155
  return {
166
156
  request: {
@@ -251,8 +241,12 @@ export default class ServerResponse<
251
241
  // fichier = fichier[0] === '/'
252
242
  // ? this.app.path.root + '/bin' + fichier
253
243
  // : this.app.path.data + '/' + fichier;
244
+ // Disk not provided = file response disabled
245
+ if (this.router.services.disks === undefined)
246
+ throw new Anomaly("Router: Unable to return file response in router, because no disk has been given in the router config.");
254
247
 
255
- const disk = this.router.config.disk;
248
+ // Retirve disk driver
249
+ const disk = this.router.services.disks.get('default');
256
250
 
257
251
  // Verif existance
258
252
  const fileExists = await disk.exists('data', fichier);
@@ -262,7 +256,7 @@ export default class ServerResponse<
262
256
  }
263
257
 
264
258
  // envoi fichier
265
- this.data = await disk.readFile('data', fichier);
259
+ this.data = await disk.readFile('data', fichier, {});
266
260
  return this.end();
267
261
  }
268
262
 
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "Core/Router",
3
+ "name": "Router",
4
+ "parent": "app",
5
+ "dependences": []
6
+ }