Add to /api/db/schema.prisma
model Request {
id String @id @default(uuid())
createdAt DateTime @default(now())
data String
origin String
}
Throw this in /api/src/functions/request.js
const { PrismaClient } = require('@prisma/client')
const dotenv = require('dotenv')
dotenv.config()
const db = new PrismaClient()
exports.handler = async (event) => {
console.log(event)
// This is where we do our business logic
await db.request.create({
data: {
data: event.body,
origin: event.requestContext.identity.sourceIp,
},
})
db.disconnect()
// This is where we return our response
return {
statusCode: 200,
body: event,
}
}Run these commands
yarn rw g scaffold request
yarn rw db save
yarn rw db up
yarn rw devNavigate to localhost:8911/request and you should see the details of your request printed on the screen.
It will also save info to the database. There are two ways to view this data:
- Open localhost:8910/requests to see them in the frontend
- Run
yarn rw db studioto use a handy database admin/inspection tool