This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
84 lines (67 loc) · 2.18 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
index.js
Entry point for the project. Here we set up our Express routes and expose
a port for the server to run on.
*/
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const args = require('minimist')(process.argv.slice(2))
const pkg = require('./package.json')
const logger = require('./helpers/logger')
const { db, getSwarm } = require('./database')
const publish = require('./routes/publish')
const fetch = require('./routes/fetch')
const search = require('./routes/search')
const requestRemove = require('./routes/requestRemove')
const verifyRemove = require('./routes/verifyRemove')
if (args.h) {
// eslint-disable-next-line
console.log(
`dat-keyserver: a distributed PGP keyserver project based on the dat protocol
Options:
-k <key> : the key of the pool you want to join
-p <port> : the port to run the HTTP server on (4000)
-s : run in seeding mode (false)
-d <path> : path to the folder in which you want to store the database (~/.datkeyserver)
See README.md for more information.`
)
process.exit(0)
}
// Express setup
app.set('view engine', 'pug')
app.set('views', './html')
app.use(express.static('html/static'))
app.use(bodyParser.urlencoded({ extended: true }))
// Render index page
app.get('/', (req, res) => {
res.render('index', {
version: pkg.version,
key: db.key.toString('hex'),
peers: getSwarm().connections.length
})
})
// Render FAQ page
app.get('/faq', (req, res) => {
res.render('faq', { version: pkg.version })
})
// HTTP route to get pool key
app.get('/key', (req, res) => {
res.send(`<pre>${db.key.toString('hex')}</pre>`)
})
// HTTP route to publish a new public key
app.post('/publish', publish)
// HTTP route to fetch a pubilc key
app.get('/fetch', fetch)
// HTTP route to search keys for a specific query
app.get('/search', search)
// HTTP route to request removal of a key
app.post('/remove/request', requestRemove)
// HTTP route to verify the removal of a key
app.post('/remove/verify', verifyRemove)
if (!args.s) {
// Start the HTTP server
const port = args.p || 4000
app.listen(port, () => logger.info(`dat-keyserver started on port ${port}`))
}
module.exports = app