-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATADOG_TOKEN="" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['weblint'], | ||
rules: { | ||
'import/no-anonymous-default-export': 'off', | ||
'import/no-anonymous-default-export': 'off', | ||
'no-use-before-define': 'off' | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "leafwatch-worker", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "GPL-3.0", | ||
"scripts": { | ||
"dev": "wrangler dev --port 8084 --local", | ||
"worker:deploy": "wrangler publish", | ||
"lint": "eslint . --ext .ts" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20230115.0", | ||
"eslint-config-weblint": "*", | ||
"tsconfig": "*", | ||
"typescript": "^4.9.5", | ||
"wrangler": "2.9.1" | ||
}, | ||
"dependencies": { | ||
"@cfworker/uuid": "^1.12.4" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { uuid } from '@cfworker/uuid'; | ||
|
||
type EnvType = { | ||
DATADOG_TOKEN: string; | ||
}; | ||
|
||
export default { | ||
async fetch(request: Request, env: EnvType) { | ||
return await handleRequest(request, env); | ||
} | ||
}; | ||
|
||
const headers = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': 'Content-Type', | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
const handleRequest = async (request: Request, env: EnvType) => { | ||
if (request.method !== 'POST') { | ||
return new Response(JSON.stringify({ success: false, message: 'Only POST requests are supported' }), { | ||
headers | ||
}); | ||
} | ||
|
||
if (request.headers.get('origin') !== 'https://lenster.xyz') { | ||
return new Response(JSON.stringify({ success: false, message: 'Origin not allowed' }), { headers }); | ||
} | ||
|
||
const payload = await request.json(); | ||
|
||
if (!payload) { | ||
return new Response(JSON.stringify({ success: false, message: 'No body provided' }), { headers }); | ||
} | ||
|
||
try { | ||
const appenedPayload = { | ||
...payload, | ||
ddsource: 'leafwatch', | ||
ip: request.headers.get('cf-connecting-ip') || 'unknown' | ||
}; | ||
const datadogRes = await fetch( | ||
`https://http-intake.logs.datadoghq.com/api/v2/logs?dd-api-key=${ | ||
env.DATADOG_TOKEN | ||
}&dd-request-id=${uuid()}`, | ||
{ | ||
method: 'POST', | ||
headers: { 'content-type': 'application/json' }, | ||
body: appenedPayload | ||
} | ||
); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
success: true, | ||
payload: appenedPayload, | ||
ddResponse: await datadogRes.json() | ||
}), | ||
{ headers } | ||
); | ||
} catch { | ||
return new Response(JSON.stringify({ success: false, message: 'Something went wrong!' }), { headers }); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "tsconfig/base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"noEmit": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name = "leafwatch-worker" | ||
main = "src/index.ts" | ||
compatibility_date = "2023-01-25" | ||
logpush = true | ||
routes = [ | ||
{ pattern = "leafwatch.lenster.xyz", custom_domain = true } | ||
] | ||
keep_vars = true | ||
|
||
[env.production.vars] | ||
DATADOG_TOKEN = "" |
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
fd38a30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
prerender – ./apps/prerender
prerender-git-main-lenster.vercel.app
prerender-lenster.vercel.app
prerender.lenster.xyz
fd38a30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web – ./apps/web
web-lenster.vercel.app
lenster.xyz
lenster.vercel.app
web-git-main-lenster.vercel.app
fd38a30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.