-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 1.11 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
const forms = require("./config/forms.js");
const testForms = require("./config/forms-test.js");
const FormHandler = require("./src/js/FormHandler.js");
exports.handler = async (event, context) => {
const testMode = process.env.TEST ? true : false;
if (!testMode) {
// console.log(
// "ENVIRONMENT VARIABLES\n" + JSON.stringify(process.env, null, 2)
// );
console.log("EVENT\n" + JSON.stringify(event, null, 2));
// console.log("CONTEXT\n" + JSON.stringify(context, null, 2));
}
const formSettings = testMode ? testForms : forms;
const handler = new FormHandler(event, formSettings, {
mailgunDomain: process.env.MAILGUN_DOMAIN,
mailgunKey: process.env.MAILGUN_API_KEY,
defaultRedirect: process.env.ROOT_REDIRECT,
slackChannel: process.env.SLACK_CHANNEL,
slackEndpoint: process.env.SLACK_ENDPOINT,
allowedOrigins: process.env.ALLOWED_ORIGINS
});
if (handler.hasValidForm()) {
if (handler.validateFormFields()) {
await handler.send();
}
}
return handler.getResponse();
};