Project-13.1/ backend
A) 1) Create folder
2) npm create hono@latest //initialize hono
3) Target directory: you can give it what you want to give
4) Chouse ColudFlair
2) npm create hono@latest //initialize hono
3) Target directory: you can give it what you want to give
4) Chouse ColudFlair
Code
B)
1) Get you neon.db OR avien.tech Connection String
2) Initialize prisma
>npx i prisma
>npx prisma init
3) Get your pool URL from the Prisma accelerator
> Copy the Database String OR Connection string
> Create a Prisma Accelerate Account
> Create a personal project
> Click to Accelerate
> Click the Setup
> Paste on "Database Connection String"
> Select reign
> Enable Accelerate
> Generate API Key
> Copy the API
> Go to the .env file and replace the old string to the original database string
> Go to the wrangler.toml and replace the old database to generated string connection
C)
migration's
1) npx prisma migrate dev --create-only
2) npx prisma generate --no-engine
3) npm install @prisma/extension-accelerate //Add the Acceleration extension
4) npx prisma migrate dev //you can now edit it and apply it by running
E)
Initialize the prisma client
code
import { prisma cient } from '@prisma/client/edge'
import { withAccelerate } from '@prisma/extension-Accelerate'
const prisma = new PrismaClient({
Bindings: {
DATABASE_URL: string
}}),$exnends(withAccelerate())
__OR__
const app = new Hono<{
Bindings: {
DATABASE_URL: string
}
}>(); F)
use hono jwt libariry
JWT secret should be present in wrangler.toml file
G)
middleware
To restricts a middleware to certain routes, you can use the following
app.use('/message/user', async(c,next) => {
awaity next()
})
In our case, the following routes need to be protected
app.use('/message/user', async(c,next) => {})
app.use('/message/user/:id', async(c,next) => {})
so, we can add top-level middleware
app.use('/message/user', async(c,next) => {
awaity next()
})
Comments