-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (48 loc) · 2.02 KB
/
Copy pathindex.js
File metadata and controls
61 lines (48 loc) · 2.02 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
57
58
59
60
61
/**
Nodejs Template Project
@author:
@version: 1.0
**/
const errorHandlerModule = require("./components/error-handler.js");
const responseObj = require("./components/response.js");
const configModule = require("./components/config.js");
const logger = require("./components/logger.js");
module.exports.handler = (event, context, cb) => {
//Initializations
const errorHandler = errorHandlerModule();
const config = configModule.getConfig(event, context);
logger.init(event, context);
try {
//Following is a code snippet to fetch values from config file:
const myVal = config.configKey;
//Following code snippet describes how to log messages within your code:
/*
logger.error('Runtime errors or unexpected conditions.');
logger.warn('Runtime situations that are undesirable or unexpected, but not necessarily "wrong".');
logger.info('Interesting runtime events (Eg. connection established, data fetched etc.)');
logger.verbose('Generally speaking, most lines logged by your application should be written as verbose.');
logger.debug('Detailed information on the flow through the system.');
*/
const sampleResponse = {
"foo": "foo-value",
"bar": "bar-value",
"configKeys": myVal
};
//Your GET method should be handled here
if (event && event.method && event.method === 'GET') {
logger.verbose(sampleResponse);
cb(null, responseObj(sampleResponse, event.query));
}
//Your POST method should be handled here
if (event && event.method && event.method === 'POST') {
cb(null, responseObj(sampleResponse, event.body));
}
} catch (e) {
//Sample Error response for internal server error
cb(JSON.stringify(errorHandler.throwInternalServerError("Sample message")));
//Sample Error response for Not Found Error
//cb(JSON.stringify(errorHandler.throwNotFoundError("Sample message")));
//Sample Error response for Input Validation Error
//cb(JSON.stringify(errorHandler.throwInputValidationError("Sample message")));
}
};