forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
112 lines (104 loc) · 2.41 KB
/
Copy pathindex.js
File metadata and controls
112 lines (104 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import 'dotenv-safe/config'
import { Database, aql } from 'arangojs'
import { Server } from './src/server'
import { createContext } from './src/create-context'
import { createI18n } from './src/create-i18n'
const {
PORT = 4000,
DB_PASS: rootPass,
DB_URL: url,
DB_NAME: databaseName,
DEPTH_LIMIT: maxDepth,
COST_LIMIT: complexityCost,
SCALAR_COST: scalarCost,
OBJECT_COST: objectCost,
LIST_FACTOR: listFactor,
TRACING_ENABLED: tracing,
HASHING_SALT,
LOGIN_REQUIRED = 'true',
} = process.env
const collections = [
'users',
'organizations',
'domains',
'dkim',
'dkimResults',
'dmarc',
'spf',
'https',
'ssl',
'dkimGuidanceTags',
'dmarcGuidanceTags',
'spfGuidanceTags',
'httpsGuidanceTags',
'sslGuidanceTags',
'chartSummaries',
'dmarcSummaries',
'aggregateGuidanceTags',
'scanSummaryCriteria',
'chartSummaryCriteria',
'scanSummaries',
'affiliations',
'claims',
'domainsDKIM',
'dkimToDkimResults',
'domainsDMARC',
'domainsSPF',
'domainsHTTPS',
'domainsSSL',
'ownership',
'domainsToDmarcSummaries',
]
;(async () => {
const db = new Database({
url,
databaseName,
auth: { username: 'root', password: rootPass },
})
const query = async function query(strings, ...vars) {
return db.query(aql(strings, ...vars), {
count: true,
})
}
const transaction = async function transaction(collections) {
return db.beginTransaction(collections)
}
const server = await Server({
context: async ({ req, res, connection }) => {
if (connection) {
// XXX: assigning over req?
req = {
headers: {
authorization: connection.authorization,
},
language: connection.language,
}
}
const i18n = createI18n(req.language)
return createContext({
query,
transaction,
collections,
req,
res,
i18n,
loginRequiredBool: LOGIN_REQUIRED === 'true', // bool not string
salt: HASHING_SALT,
})
},
maxDepth,
complexityCost,
scalarCost,
objectCost,
listFactor,
tracing,
})
console.log(
`Starting server with "LOGIN_REQUIRED" set to "${LOGIN_REQUIRED}"`,
)
await server.listen(PORT, (err) => {
if (err) throw err
console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`)
console.log(`🚀 Subscriptions ready at ws://localhost:${PORT}/graphql`)
})
})()