File tree Expand file tree Collapse file tree 2 files changed +36
-15
lines changed Expand file tree Collapse file tree 2 files changed +36
-15
lines changed Original file line number Diff line number Diff line change 1
- import { ServerFactory , AppConfig } from '../src/index' ;
2
1
import express from 'express' ;
2
+ import {
3
+ AppConfig ,
4
+ Swagger ,
5
+ SwaggerConfig ,
6
+ CloudEnvironment ,
7
+ CoreApp ,
8
+ FileStorageAdapter ,
9
+ Environment ,
10
+ } from '../src/index' ;
3
11
4
12
const server = express ( ) ;
5
- const defaultConfig = new AppConfig ( ) ;
6
- defaultConfig . readOnly = false ;
7
- defaultConfig . jsonFile = 'db.json' ;
13
+ const appConfig = new AppConfig ( ) ;
8
14
9
- const start = async ( ) => {
10
- // do something
11
- await ServerFactory . createServer (
12
- 'local' ,
13
- server ,
14
- defaultConfig ,
15
- './package.json'
15
+ const environment = new Environment ( ) ;
16
+ const swagger = new Swagger (
17
+ server ,
18
+ new SwaggerConfig ( appConfig . readOnly , appConfig . enableApiKeyAuth ) ,
19
+ environment . basePath ,
20
+ appConfig . apiRoutePath ,
21
+ './package.json'
22
+ ) ;
23
+
24
+ let core : CoreApp | undefined ;
25
+ core = new CoreApp (
26
+ appConfig ,
27
+ server ,
28
+ new FileStorageAdapter ( 'db.json' ) ,
29
+ swagger ,
30
+ environment
31
+ ) ;
32
+
33
+ const init = async ( ) => {
34
+ await core ! . setup ( ) ;
35
+ console . log (
36
+ 'JSON Server is running under port 3000. Use http://localhost:3000/ to access it'
16
37
) ;
38
+ server . listen ( 3000 ) ;
17
39
} ;
18
-
19
- start ( ) ;
40
+ const initPromise = init ( ) ;
Original file line number Diff line number Diff line change 10
10
},
11
11
"scripts" : {
12
12
"test" : " npx jest" ,
13
- "debug" : " nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec node --inspect-brk -r ts-node/register example/index.ts" ,
14
- "start" : " nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' example/index.ts" ,
13
+ "debug" : " nodemon --watch 'src/**/*.ts' --watch 'example/index.ts' -- ignore 'src/**/*.spec.ts' --exec node --inspect-brk -r ts-node/register example/index.ts" ,
14
+ "start" : " nodemon --watch 'src/**/*.ts' --watch 'example/index.ts' -- ignore 'src/**/*.spec.ts' --exec 'ts-node' example/index.ts" ,
15
15
"type-check" : " tsc --noEmit" ,
16
16
"type-check:watch" : " npm run type-check -- --watch" ,
17
17
"build" : " tsc -b" ,
You can’t perform that action at this time.
0 commit comments