meetnearme / api

1 stars 0 forks source link

Cloudflare KV Edge Lookup for Subdomains #115

Closed brianfeister closed 2 weeks ago

brianfeister commented 3 weeks ago

This PR is a partial / first pass, introducing

  1. An API endpoint for adding a new item to KV store from within your /admin/profile section
  2. An appended header that is (for now) the user ID of the user who added that header. This header will be used to make "scoped" DB requests that only show "events owned by org with ID "

Testing this

  1. Go to https://testingnear.me/admin/profile (has to be a test env that has cloudflare in front of it)
  2. Add a value in the Set Subdomain input field
  3. Hit Update Subdomain
  4. Open a new browser tab
  5. Open Dev Tools
  6. Go to <subdomain>.testingnear.me
  7. Look for the main request for that page and verify that there is a header X-Mnm-Subdomain-Value and that it's value is the same as what you see for ID under "My Info" on /admin/profile image

Problems

~⚠️ Users can currently "grab" multiple subdomains and we need logic to prevent abuse / greedy subdomain grabbing~ (this is fixed now, see screenshot)

https://github.com/user-attachments/assets/b14e1b5f-7de2-495e-ac34-0370035fdfad

image

brianfeister commented 3 weeks ago

I'm hoping to get the coverage up and stick to our promise to ourselves. Admittedly, it's a bit tough with our tight timeline

brianfeister commented 2 weeks ago

Coverage resolved @Brandon-G-Tripp 43% => 53.5% mocking that new controller I just added for the KV work. LFG!!! 🔥 Let's merge this before things get crazier.

Cursor.ai did insane heavy lifting getting me through writing that test... was quite a big chunk of code. 💪