-
-
Save JonMerlevede/71e978b7e1522a7d911e456570e23f23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Request, Response } from "express" | |
import fetch from "node-fetch" | |
export const main: HttpFunction = (req: Request, res: Response) => { | |
if (corsHandler(req, res)) { return } | |
if (!Array.isArray(req.body)) { res.status(400).send("invalid request; no array"); return } | |
// Get environment (dev, test, acc, prod, ...) | |
const env = getAuth0Tenant(req) | |
// Map log data onto payload data elements ~ JSON tracker protocol | |
const payloads = req.body.map(e => auth0LogToPayloadDataElement(env, e.data)) | |
// Put payload data elements in payload_data envelope | |
const envelopedPayload = envelopIgluDataPayloads(payloads) | |
// Send to sp colelctor; don't actually wait for the result of the request | |
fetch("https://sp.acme.com/com.snowplowanalytics.snowplow/tp2", { | |
method: "post", | |
body: JSON.stringify(envelopedPayload), | |
headers: { | |
"Content-Type": "application/json" | |
} | |
}) | |
res.send("ok") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment