@@ -8,6 +8,7 @@ import fastifyStatic from "@fastify/static";
8
8
import fastifyMetrics from "fastify-metrics" ;
9
9
import fastifyQs from "fastify-qs" ;
10
10
import * as path from "path" ;
11
+ import ConfigService from "../../utils/Config" ;
11
12
12
13
export default class Api {
13
14
static _instance : Api
@@ -34,9 +35,10 @@ export default class Api {
34
35
}
35
36
36
37
async start ( ) : Promise < void > {
37
- await this . registerPlugins ( )
38
+ const config = ConfigService . getInstance ( ) . config !
39
+ await this . registerPlugins ( config . apiStaticPrefix , config . apiMetricsPath )
38
40
39
- this . fastify . listen ( { port : 3000 } , ( err , address ) => {
41
+ this . fastify . listen ( { port : config . apiPort } , ( err , address ) => {
40
42
if ( err ) {
41
43
this . fastify . log . error ( err )
42
44
process . exit ( 1 )
@@ -48,7 +50,7 @@ export default class Api {
48
50
await this . fastify . close ( )
49
51
}
50
52
51
- async registerPlugins ( ) : Promise < void > {
53
+ async registerPlugins ( staticPrefix : string , metricsPath : string ) : Promise < void > {
52
54
this . fastify . register ( fastifyAutoload , {
53
55
dir : __dirname + '/routes' ,
54
56
} )
@@ -84,7 +86,7 @@ export default class Api {
84
86
console . log ( __dirname )
85
87
this . fastify . register ( fastifyStatic , {
86
88
root : path . join ( __dirname , '/public' ) ,
87
- prefix : '/public/' ,
89
+ prefix : staticPrefix ,
88
90
constraints : { host : 'example.com' }
89
91
} )
90
92
@@ -97,7 +99,7 @@ export default class Api {
97
99
98
100
// https://gitlab.com/m03geek/fastify-metrics
99
101
this . fastify . register ( fastifyMetrics , {
100
- endpoint : '/metrics' ,
102
+ endpoint : metricsPath ,
101
103
} )
102
104
103
105
// https://www.npmjs.com/package/fastify-qs
0 commit comments