Build a small app where a user can create a secret message and get a link to share. When someone opens the link, they can read the message once, and then it’s gone.
store data in memory using an array.
- Create a file like
lib/store.ts - Export an array to hold secrets
Each item in the array should look like: { id: string, text: string, createdAt: number }
This runs on the server, so the data will persist while the dev server is running. Of course data resets on server restart without a DB.
- Validate request body contains
text. - Generate a random id (string)
- Store using in array with
push - Respond with { "id": "abc123" }
- Find the message in the array with
find. - If it exists:
- return it
- remove it using from the array with
filter
- If not:
- return a 404 status
- Form with input field
- “Create secret link” submit button
- On submit:
- POST message
- show generated link like
localhost:3000/secret/${id}
- Fetch message
- Show message if found
- If not show “Not Found”
Focus on getting it working, don't worry about styling.