week 11.1 serverles function, prisma, hono
1. Initializing a worker
//To create and deploy you application, you cna take the following stepsnpm create cloudflare -- my-aap
2. to signup page of cloudflare
npx wrangler login3. to deploy you code
npm run dev
===============hono application=======
1. initialize a new app
npm create hono@latest my-app
1. move to my-app and install the dependencies.
cd my-app
npm i
this is syntax of sending data in body, header, parems and bunch of things#
import { Hono } from 'hono'
const app = new Hono()
app.get('/', async (c) => {
//body, headers, query parameters, middlewares, connecting to a database
const body = await c.req.json()
console.log(body);
console.log(c.req.header("Authorization"));
console.log(c.req.query("param"));
return c.text('Hello Hono!')
})
export default app
//middleware
import { Hono, Next } from 'hono'
import { Context } from 'hono/jsx';
const app = new Hono()
app.use(async (c, next) => {
if (c.req.header("Authorization")) {
// Do validation
await next()
} else {
return c.text("You dont have acces");
}
})
app.get('/', async (c) => {
const body = await c.req.parseBody()
console.log(body);
console.log(c.req.header("Authorization"));
console.log(c.req.query("param"));
return c.json({msg: "as"})
})
export default app //connecting database
npm install --save-dev prisma2. Init Prisma
npx prisma init 3. Create a basic schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
name String
email String
password String
}Create migrations
npx prisma migrate dev --name init5. Signup to Prisma accelerate
https://console.prisma.io/login
Comments