@@ -3,9 +3,9 @@ import { LogService } from "./w3id/log-service";
3
3
import { GraphQLServer } from "./protocol/graphql-server" ;
4
4
import { registerHttpRoutes } from "./http/server" ;
5
5
import fastify , {
6
- FastifyInstance ,
7
- FastifyRequest ,
8
- FastifyReply ,
6
+ FastifyInstance ,
7
+ FastifyRequest ,
8
+ FastifyReply ,
9
9
} from "fastify" ;
10
10
import { renderVoyagerPage } from "graphql-voyager/middleware" ;
11
11
import { createYoga } from "graphql-yoga" ;
@@ -17,80 +17,89 @@ import { W3ID } from "./w3id/w3id";
17
17
dotenv . config ( { path : path . resolve ( __dirname , "../../../.env" ) } ) ;
18
18
19
19
class EVault {
20
- server : FastifyInstance ;
21
- graphqlServer : GraphQLServer ;
22
- logService : LogService ;
23
- driver : Driver ;
24
-
25
- constructor ( ) {
26
- const uri = process . env . NEO4J_URI || "bolt://localhost:7687" ;
27
- const user = process . env . NEO4J_USER || "neo4j" ;
28
- const password = process . env . NEO4J_PASSWORD || "neo4j" ;
29
-
30
- if (
31
- ! process . env . NEO4J_URI ||
32
- ! process . env . NEO4J_USER ||
33
- ! process . env . NEO4J_PASSWORD
34
- ) {
35
- console . warn (
36
- "Using default Neo4j connection parameters. Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables for custom configuration."
37
- ) ;
20
+ server : FastifyInstance ;
21
+ graphqlServer : GraphQLServer ;
22
+ logService : LogService ;
23
+ driver : Driver ;
24
+
25
+ constructor ( ) {
26
+ const uri = process . env . NEO4J_URI || "bolt://localhost:7687" ;
27
+ const user = process . env . NEO4J_USER || "neo4j" ;
28
+ const password = process . env . NEO4J_PASSWORD || "neo4j" ;
29
+
30
+ if (
31
+ ! process . env . NEO4J_URI ||
32
+ ! process . env . NEO4J_USER ||
33
+ ! process . env . NEO4J_PASSWORD
34
+ ) {
35
+ console . warn (
36
+ "Using default Neo4j connection parameters. Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables for custom configuration." ,
37
+ ) ;
38
+ }
39
+
40
+ this . driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ) ;
41
+
42
+ const dbService = new DbService ( this . driver ) ;
43
+ this . logService = new LogService ( this . driver ) ;
44
+ this . graphqlServer = new GraphQLServer ( dbService ) ;
45
+
46
+ this . server = fastify ( {
47
+ logger : true ,
48
+ } ) ;
38
49
}
39
50
40
- this . driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ) ;
41
-
42
- const dbService = new DbService ( this . driver ) ;
43
- this . logService = new LogService ( this . driver ) ;
44
- this . graphqlServer = new GraphQLServer ( dbService ) ;
45
-
46
- this . server = fastify ( {
47
- logger : true ,
48
- } ) ;
49
- }
50
-
51
- async initialize ( ) {
52
- await registerHttpRoutes ( this . server ) ;
53
-
54
- const w3id = await W3ID . get ( {
55
- id : process . env . W3ID as string ,
56
- driver : this . driver ,
57
- password : process . env . ENCRYPTION_PASSWORD ,
58
- } ) ;
59
-
60
- const yoga = this . graphqlServer . init ( ) ;
61
-
62
- this . server . route ( {
63
- // Bind to the Yoga's endpoint to avoid rendering on any path
64
- url : yoga . graphqlEndpoint ,
65
- method : [ "GET" , "POST" , "OPTIONS" ] ,
66
- handler : ( req , reply ) =>
67
- yoga . handleNodeRequestAndResponse ( req , reply , {
68
- req,
69
- reply,
70
- } ) ,
71
- } ) ;
72
-
73
- // Mount Voyager endpoint
74
- this . server . get ( "/voyager" , ( req : FastifyRequest , reply : FastifyReply ) => {
75
- reply . type ( "text/html" ) . send (
76
- renderVoyagerPage ( {
77
- endpointUrl : "/graphql" ,
78
- } )
79
- ) ;
80
- } ) ;
81
- }
82
-
83
- async start ( ) {
84
- await this . initialize ( ) ;
85
-
86
- const port = process . env . NOMAD_PORT_http || process . env . PORT || 4000 ;
87
-
88
- await this . server . listen ( { port : Number ( port ) , host : "0.0.0.0" } ) ;
89
- console . log ( `Server started on http://0.0.0.0:${ port } ` ) ;
90
- console . log ( `GraphQL endpoint available at http://0.0.0.0:${ port } /graphql` ) ;
91
- console . log ( `GraphQL Voyager available at http://0.0.0.0:${ port } /voyager` ) ;
92
- console . log ( `API Documentation available at http://0.0.0.0:${ port } /docs` ) ;
93
- }
51
+ async initialize ( ) {
52
+ await registerHttpRoutes ( this . server ) ;
53
+
54
+ const w3id = await W3ID . get ( {
55
+ id : process . env . W3ID as string ,
56
+ driver : this . driver ,
57
+ password : process . env . ENCRYPTION_PASSWORD ,
58
+ } ) ;
59
+
60
+ const yoga = this . graphqlServer . init ( ) ;
61
+
62
+ this . server . route ( {
63
+ // Bind to the Yoga's endpoint to avoid rendering on any path
64
+ url : yoga . graphqlEndpoint ,
65
+ method : [ "GET" , "POST" , "OPTIONS" ] ,
66
+ handler : ( req , reply ) =>
67
+ yoga . handleNodeRequestAndResponse ( req , reply , {
68
+ req,
69
+ reply,
70
+ } ) ,
71
+ } ) ;
72
+
73
+ // Mount Voyager endpoint
74
+ this . server . get (
75
+ "/voyager" ,
76
+ ( req : FastifyRequest , reply : FastifyReply ) => {
77
+ reply . type ( "text/html" ) . send (
78
+ renderVoyagerPage ( {
79
+ endpointUrl : "/graphql" ,
80
+ } ) ,
81
+ ) ;
82
+ } ,
83
+ ) ;
84
+ }
85
+
86
+ async start ( ) {
87
+ await this . initialize ( ) ;
88
+
89
+ const port = process . env . NOMAD_PORT_http || process . env . PORT || 4000 ;
90
+
91
+ await this . server . listen ( { port : Number ( port ) , host : "0.0.0.0" } ) ;
92
+ console . log ( `Server started on http://0.0.0.0:${ port } ` ) ;
93
+ console . log (
94
+ `GraphQL endpoint available at http://0.0.0.0:${ port } /graphql` ,
95
+ ) ;
96
+ console . log (
97
+ `GraphQL Voyager available at http://0.0.0.0:${ port } /voyager` ,
98
+ ) ;
99
+ console . log (
100
+ `API Documentation available at http://0.0.0.0:${ port } /docs` ,
101
+ ) ;
102
+ }
94
103
}
95
104
96
105
const evault = new EVault ( ) ;
0 commit comments