This is a Next.js project bootstrapped with create-next-app.
I followed the tutorial here with some minor changes.
npx create-next-appwith name: calculation-brainstorm- push repo to github
- deploy repo on Vercel by adding a new Project which imports the github repo
- create a Postgres database and connect it to the Project
npm i -g vercel@latestnpm i @vercel/postgresvercel linkThis step was omitted from the tutorialvercel env pull .env.development.local- make sure
.env.development.localexists locally and that the variables in that file match the ones in the Vercel project npm run dev- create file at path:
src/app/api/test/route.ts - visit
http://localhost:3000/api/testwhich creates a table in the db which can be seen in the Vercel dashboard - create file at path:
src/app/api/addPet/route.ts - visit
http://localhost:3000/api/addPet?petName=Johnny&ownerName=Markwhich adds a row to the table that was just created
Switch from src/app to src/pages
npm install @nostr-dev-kit/ndk
npm install @noble/hashes
npm install nostr-tools
npm install nostr-hooks
Thought I needed to do these but I uninstalled them and still seems to work.
npm install ws
npm install websocket-polyfill
# then on any nostr page:
import 'websocket-polyfill
To fix CORS problems, add vercel.json:
{
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
{ "key": "Access-Control-Allow-Origin", "value": "*" },
{ "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
{ "key": "Access-Control-Allow-Headers", "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }
]
}
]
}
How data is scraped from generic nostr relays
- https://calculation-brainstorm.vercel.app/api/grapevine/addNewCustomer?pubkey=pk_customer
- add pk_customer to customers table
- STEP 1: https://interpretation-brainstorm.vercel.app/api/nostr/listeners/singleUser?pubkey=pk_customer
- add pk_customer to users table
- listen for kind 3 and 10000 notes for pk_customer; add pubkeys to users.mutes and users.follows
- STEP 2: https://interpretation-brainstorm.vercel.app/api/manageData/singleUser/insertFollowsAndMutesIntoUsersTable?pubkey=pk_customer
- for pk_customer, insert pubkeys from users.follows and users.mutes into users, so that they all have a userID
- STEP 3: https://interpretation-brainstorm.vercel.app/api/manageData/singleUser/createObserverObject?pubkey=pk_customer
- for pk_customer, create observerObject, which is ultra compact (prefers userIDs; 'f' and 'm' format)
- erase users.follows and users.mutes once observerObject is created (to minimize size of users database and speed up queries)
- not yet created: https://interpretation-brainstorm.vercel.app/api/nostr/listeners/singleUserFollows?pubkey=pk_customer
- listen for kind 3 and 10000 notes for all follows of pk_customer in blocks of no more than 1000; do not repeat if this step is already achieved; add pubkeys to users.mutes and users.follows
- https://interpretation-brainstorm.vercel.app/api/manageData/singleUser/createDosSummary?pubkey=pk_customer
- for pk_customer, create DoS summary and store in table: dosSummaries
- not yet created:
- for pk_customer, create RatingsTables -- ??? do it quickly using DoS data plus users.observerObjects
In customers table, or maybe make another table, need:
- column fo ScoreCards in ultra-compact format (userID and f, m format)
- which endpoint?
- listen for kind 3 and 10000 notes for all users who need it, in blocks of no more than 1000
- STEP 1:
- STEP 2: http://interpretation-brainstorm.vercel.app/api/manageData/blockOfUsers/insertFollowsAndMutesIntoUsersTable
- insert pubkeys from users.follows and users.mutes as new rows into users, so that they all have a userID
- also set users.follows=[] and users.mutes=[] after the transfer
- THIS IS THE SLOWEST STEP. need to speed it up. A way to batch multiple INSERTS???
- STEP 3:
First, run the development server:
vercel dev
# or
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.