-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (44 loc) · 1.38 KB
/
app.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
const express = require("express")
const app = express()
const bodyParser = require("body-parser")
const utils = require(`${__dirname}/../util`)
const routes = require(`${__dirname}/routes`)
const events = require(`${__dirname}/events`)
const https = require("https")
class HelloSync {
constructor (c) {
const hellosign = require("hellosign-sdk")({key: c.hellosign.key});
this.hellosign = hellosign
this.events = events
this.utils = utils
this.log = utils.log
this.auth = utils.auth
this.c = c
this.app = app
this.app.use(bodyParser.text())
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({
extended: true
}));
this.app.get("/", routes.main.bind(this))
this.app.post("/signature", routes.signature.bind(this))
this.startServer()
}
async startServer() {
this.events.connection(this)
if(this.c.secure) {
let privateKey = fs.readFileSync("key.pem");
let certificate = fs.readFileSync("cert.pem");
https.createServer({
key: privateKey,
cert: certificate
}, this.app).listen(this.c.securePort);
this.log.success(`Secure server listening on port ${this.c.securePort}`)
} else {
this.app.listen(this.c.port, () => {
this.log.success(`Server listening on port ${this.c.port}`)
})
}
}
}
module.exports = HelloSync;