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

switch simple analytics proxy to a netlify function

This commit is contained in:
2020-08-08 00:13:07 -04:00
parent d9833c6d30
commit 76b3a55efd
10 changed files with 396 additions and 111 deletions

View File

@@ -1,12 +0,0 @@
export async function handler(event, context) {
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "Hello from the other side...",
lucky_num: `${Math.floor(Math.random() * 100)}`,
}),
};
}

45
functions/send_view.js Normal file
View File

@@ -0,0 +1,45 @@
const request = require("request");
exports.handler = function (event, context, callback) {
const reqHeaders = {
referer: event.headers["referer"],
"user-agent": event.headers["user-agent"],
};
const reqQuery = event.queryStringParameters;
reqQuery["ignore-dnt"] = true; // this isn't nefarious, we're not tracking in the first place!
const reqOptions = {
method: "GET",
url: "https://queue.simpleanalyticscdn.com/simple.gif",
headers: reqHeaders,
qs: reqQuery,
};
request(reqOptions, (error, response, body) => {
if (error) {
console.error(error);
callback(null, {
statusCode: 500,
});
} else {
console.info(response.statusCode, response.headers["simple-analytics-feedback"]);
const resHeaders = {
"content-type": response.headers["content-type"],
"cache-control": "no-cache, no-store, must-revalidate",
expires: "0",
pragma: "no-cache",
"x-api-feedback": response.headers["simple-analytics-feedback"],
"x-api-destination": response.headers["simple-analytics-location"],
};
callback(null, {
statusCode: response.statusCode,
headers: resHeaders,
body: body,
});
}
});
};