-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
52 lines (49 loc) · 1.39 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
'use strict';
const EnvelopeEncrypt = require('./lib/EnvelopeEncrypt.js');
const encryptor = new EnvelopeEncrypt();
const fs = require('fs');
const path = require('path');
module.exports.get = (event, context, callback) => {
encryptor.loadData(event.pathParameters.id)
.then((payload) => {
callback(null,{
"statusCode": 200,
"body": JSON.stringify(payload)
});
})
.catch((err) => {
callback(null,{
"statusCode": 404,
"body": 'Not found'
});
});
};
module.exports.create = (event, context, callback) => {
encryptor.saveData(JSON.parse(event.body))
.then((res) => {
callback(null,{
"statusCode": 200,
"body": '{"status":"ok","uuid":"'+res+'"}'
});
})
.catch((err) => {
callback(null,{
"statusCode": 500,
"body": JSON.stringify(err)
});
});
};
module.exports.index = (event, context, callback) => {
callback(null,{
"statusCode": 200,
"headers": {"content-type": "text/html"},
"body": fs.readFileSync(
path.resolve(
process.env.LAMBDA_TASK_ROOT,
'_optimize',
process.env.AWS_LAMBDA_FUNCTION_NAME,
"ui/index.html"
)
).toString()
});
};