File tree 3 files changed +42
-1
lines changed
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ You should receive the following response:
93
93
}
94
94
```
95
95
96
+ You can also try the following call:
97
+ ``` bash
98
+ curl --request GET \
99
+ --url http://127.0.0.1:5003/config
100
+ ```
101
+
96
102
You can see the code and registered route here:
97
103
https://github.com/learn-ark/dapp-core-module-http-server-template/blob/master/src/server.ts#L49-L56 .
98
104
Original file line number Diff line number Diff line change
1
+ import { app } from "@arkecosystem/core-container" ;
2
+ import { Plugins } from "@arkecosystem/core-utils" ;
3
+
4
+ export const config = {
5
+ async handler ( ) {
6
+ const appConfig = app . getConfig ( ) ;
7
+
8
+ return {
9
+ data : {
10
+ version : app . getVersion ( ) ,
11
+ network : {
12
+ version : appConfig . get ( "network.pubKeyHash" ) ,
13
+ name : appConfig . get ( "network.name" ) ,
14
+ nethash : appConfig . get ( "network.nethash" ) ,
15
+ explorer : appConfig . get ( "network.client.explorer" ) ,
16
+ token : {
17
+ name : appConfig . get ( "network.client.token" ) ,
18
+ symbol : appConfig . get ( "network.client.symbol" ) ,
19
+ } ,
20
+ } ,
21
+ plugins : Plugins . transformPlugins ( appConfig . config . plugins ) ,
22
+ } ,
23
+ } ;
24
+ } ,
25
+ config : {
26
+ cors : true ,
27
+ } ,
28
+ } ;
Original file line number Diff line number Diff line change 1
1
import { app } from "@arkecosystem/core-container" ;
2
- import { createServer , mountServer } from "@arkecosystem/core-http-utils" ;
2
+ import { createServer , mountServer , plugins } from "@arkecosystem/core-http-utils" ;
3
3
import { Logger } from "@arkecosystem/core-interfaces" ;
4
4
import Hapi from "@hapi/hapi" ;
5
+ import * as handlers from "./handlers" ;
5
6
6
7
export class Server {
7
8
private logger = app . resolvePlugin < Logger . ILogger > ( "logger" ) ;
@@ -47,6 +48,10 @@ export class Server {
47
48
}
48
49
49
50
private static async registerRoutes ( name : string , server : Hapi . Server ) : Promise < void > {
51
+ await server . register ( {
52
+ plugin : plugins . corsHeaders ,
53
+ } ) ;
54
+
50
55
server . route ( {
51
56
method : "GET" ,
52
57
path : "/" ,
@@ -55,6 +60,8 @@ export class Server {
55
60
} ,
56
61
} ) ;
57
62
63
+ server . route ( [ { method : "GET" , path : "/config" , ...handlers . config } ] ) ;
64
+
58
65
await mountServer ( `Custom HTTP Public ${ name . toUpperCase ( ) } API` , server ) ;
59
66
}
60
67
}
You can’t perform that action at this time.
0 commit comments