1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-18 15:25:33 -04:00

clean up send_view function

This commit is contained in:
2020-10-07 09:06:26 -04:00
parent 9543aaa5b0
commit cdc39f7efe
3 changed files with 31 additions and 48 deletions

View File

@@ -1,5 +1,4 @@
const axios = require("axios");
const { v4: uuidv4 } = require("uuid");
exports.handler = function (event, context, callback) {
try {
@@ -43,16 +42,14 @@ exports.handler = function (event, context, callback) {
timeout: 2000,
})
.then(function (response) {
console.info(
`${response.status} ${response.statusText} | ${response.elapsedTime}ms | ${response.headers["simple-analytics-feedback"]}`
);
// parse the feedback message from endpoint
const apiFeedback = response.headers["simple-analytics-feedback"] || "No feedback from Simple Analytics.";
const shortFeedback = apiFeedback.toLowerCase().includes("thanks for sending ")
? "OK"
: `ERROR: ${apiFeedback}`;
console.info(`${response.status} ${response.statusText} | ${response.elapsedTime}ms | ${apiFeedback}`);
// reasoning for base64 encoding:
// https://community.netlify.com/t/debugging-a-function-returns-502/429/12
callback(null, {
@@ -62,10 +59,8 @@ exports.handler = function (event, context, callback) {
"Cache-Control": "private, no-cache, no-store, must-revalidate",
Expires: "0",
Pragma: "no-cache",
"x-api-endpoint": endpointHost,
"x-api-response": shortFeedback,
"x-api-feedback": shortFeedback,
"x-api-latency": response.elapsedTime,
"x-api-id": uuidv4(),
},
body: response.data.toString("base64"),
isBase64Encoded: true,