-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (49 loc) · 1.36 KB
/
server.js
File metadata and controls
56 lines (49 loc) · 1.36 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
const bodyParser = require('body-parser');
const express = require('express');
const hellosign = require('hellosign-sdk');
const path = require('path');
const app = express();
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '/dist')));
app.post('/create-signature-request', (req, res) => {
const { apiKey, clientId } = req.body;
const client = hellosign({
key: apiKey,
client_id: clientId,
});
client.signatureRequest.createEmbedded({
test_mode: 1,
subject: 'NDA with Acme Co.',
message: 'Please sign this NDA and then we can discuss more.',
allow_decline: 1,
signers: [
{
email_address: 'alice@example.com',
name: 'Alice',
order: 0,
},
],
cc_email_addresses: ['bob@example.com'],
files: [path.join(__dirname, 'files/nda.docx')],
}).then((data) => {
const firstSignature = data.signature_request.signatures[0];
const signatureId = firstSignature.signature_id;
client.embedded.getSignUrl(signatureId).then((signatureData) => {
res.json({
success: true,
data: {
signUrl: signatureData.embedded.sign_url,
},
});
});
}).catch(() => {
res.json({
success: false,
});
});
});
app.listen(process.env.PORT || 3000, (err) => {
if (!err) {
console.log('Server running at http://locahost:3000');
}
});