d1-json
v0.0.5
Published
JSON CRUD + Search Functions for Cloudflare D1
Downloads
1
Readme
d1-json
JSON CRUD + Search Functions for Cloudflare D1
npm i d1-json
import { DB } from 'd1-json'
export default {
fetch: (req, env, ctx) => {
const db = DB(env)
const timestamp = Date.now()
const { hostname, pathname, search } = new URL(url)
const { colo, city, country, postalCode } = req.cf
const headers = JSON.fromEntries(req.headers)
const ip = headers['cf-ip']
const event = { timestamp, url, method, ip, headers, colo, city, country, postalCode }
ctx.waitUntil(db.logs.insert(event))
return Response.json(event)
}
}