Skip to content

Commit

Permalink
Update worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-lippert authored Sep 29, 2023
1 parent 0013996 commit 1bf1d71
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ let instanceRequests = 0
export default {
fetch: async (req, env, ctx) => {
async function logMongo(data, isError = false) {
if (isError) {
console.error('彡', 'logs.errors.ctx.do', data)
} else {
console.log('彡', 'logs.logs.ctx.do', data)
}
// if (isError) {
// console.error('彡', 'logs.errors.ctx.do', data)
// } else {
// console.log('彡', 'logs.logs.ctx.do', data)
// }
if (env.MONGO_ENDPOINT)
return await fetch(env.MONGO_ENDPOINT + '/action/insertOne', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*',
'api-key': env.MONGO_APIKEY,
},
body: `{
"dataSource": "logs",
"database": "${isError ? 'errors' : 'logs'}",
"collection": "ctx.do",
"document": ${data}
}`
})
}

let body = ''
Expand Down

0 comments on commit 1bf1d71

Please sign in to comment.