This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (50 loc) · 1.7 KB
/
index.js
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
const express = require('express')
const cron = require('node-cron')
const ApolloServer = require('apollo-server-express').ApolloServer
const { getSecret } = require('./src/secretManager.js')
const typeDefs = require('./src/schema.js')
const resolvers = require('./src/resolvers.js')
// const initWebhooks = require('./src/webhooks.js')
const DB = require('./src/db/db')
const IncidentStorage = require('./src/db/incidentStorage')
const OctokitHelper = require('./src/git/ocotokitHelper')
const Frontmatter = require('./src/db/frontmatter.js')
const app = express()
app.use(express.json())
const octokitHelper = new OctokitHelper(getSecret('token'), getSecret('owner'), getSecret('incident_repo'))
const db = new DB()
const incidentStorage = new IncidentStorage(db, octokitHelper, new Frontmatter())
incidentStorage.loadData()
cron.schedule('0 0 * * *', () => {
incidentStorage.refreshDB()
})
new ApolloServer({
typeDefs,
resolvers,
tracing: true,
context: async ({ req }) => {
return {
getSecret,
incidentStorage
}
}
}).applyMiddleware({ app, path: '/graphql', cors: true })
app.get('/', (req, res) => {
res.send(`
<title>anyway API</title>
View the API at <a href="./graphql">./graphql</a><br>
Call the self update script with POST at ./self_update<br>
<hr>
Repo: <a href="https://github.com/anyway-koeln/api-server">https://github.com/anyway-koeln/api-server</a>
`)
})
// initWebhooks(app)
const port = 4000
const host = '0.0.0.0' // Uberspace wants 0.0.0.0
app.listen({ port, host }, () =>
console.info(`
🚀 Server ready
View the API at http://${host}:${port}/graphql
Call the self update script at http://${host}:${port}/self_update
`)
)