-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
42 lines (33 loc) · 1.12 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
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const ipWhitelist = require('ip-whitelist')
const app = express()
const graphQLHTTP = require('express-graphql').graphqlHTTP
mongoose.connect(process.env.DB_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(console.log('Database connected'))
// load peer information in the database into WireGuard CLI
require('./wg/index').init()
.then(console.log('WireGuard initialized'))
// start the server
app.listen(process.env.PORT)
console.log('Server running')
/*
* // debugging code to find your IP address
*app.use((req, res, next) => {
* console.log(req.connection.remoteAddress)
* next()
*})
*/
// set up IP whitelisting for basic access control
app.use(ipWhitelist(ipWhitelist.array(process.env.WHITELISTED_IPS.split(','))))
// setup GraphQL route
app.use('/', graphQLHTTP({
schema: require('./api/index'),
graphiql: process.env.ENABLE_GRAPHIQL
}))
// periodically check the WireGuard CLI for updates
setInterval(require('./heartbeat/index'), process.env.CHECK_STATUS_INTERVAL)