File tree Expand file tree Collapse file tree 9 files changed +69
-24
lines changed
Expand file tree Collapse file tree 9 files changed +69
-24
lines changed Original file line number Diff line number Diff line change 1- MONGO_URI = " mongodb url"
1+ DATABASE_URL = " mongodb url"
22BEARER_TOKEN = " 256-bit WEP secret key"
Original file line number Diff line number Diff line change 44 "deploy" : " wrangler deploy --minify src/index.ts"
55 },
66 "dependencies" : {
7+ "@prisma/client" : " ^5.15.0" ,
78 "@types/bun" : " ^1.1.3" ,
89 "hono" : " ^4.4.4" ,
910 "mongoose" : " ^8.4.1"
1011 },
1112 "devDependencies" : {
1213 "@cloudflare/workers-types" : " ^4.20240529.0" ,
14+ "@types/node" : " ^20.14.2" ,
1315 "bun-types" : " ^1.1.12" ,
16+ "prisma" : " ^5.15.0" ,
17+ "ts-node" : " ^10.9.2" ,
18+ "typescript" : " ^5.4.5" ,
1419 "wrangler" : " ^3.57.2"
1520 }
1621}
Original file line number Diff line number Diff line change 1+ // This is your Prisma schema file,
2+ // learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+ // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5+ // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
6+
7+ generator client {
8+ provider = " prisma-client-js "
9+ }
10+
11+ datasource db {
12+ provider = " mongodb "
13+ url = env (" DATABASE_URL " )
14+ }
15+
16+ model Store {
17+ id String @id @default (auto () ) @map (" _id " ) @db.ObjectId
18+ name String
19+ storeKey String
20+ data Data []
21+ }
22+
23+ model Data {
24+ id String @id @default (auto () ) @map (" _id " ) @db.ObjectId
25+ storeId String @db.ObjectId
26+ value String
27+ store Store @relation (fields : [storeId ] , references : [id ] )
28+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { Context } from 'hono'
2+
3+ export const createStore = async ( c : Context ) => {
4+ return c . json ( { message : "Store created" } )
5+ }
Original file line number Diff line number Diff line change 1+ import { PrismaClient } from '@prisma/client'
2+
3+ const prismaClientSingleton = ( ) => {
4+ return new PrismaClient ( )
5+ }
6+
7+ type PrismaClientSingleton = ReturnType < typeof prismaClientSingleton >
8+
9+ const globalForPrisma = globalThis as unknown as {
10+ prisma : PrismaClientSingleton | undefined
11+ }
12+
13+ const prisma = globalForPrisma . prisma ?? prismaClientSingleton ( )
14+
15+ export default prisma
16+
17+ if ( process . env . NODE_ENV !== 'production' ) globalForPrisma . prisma = prisma
Original file line number Diff line number Diff line change 11import { Hono } from 'hono'
2- import connectDB from "./config/db"
32import { bearerAuth } from 'hono/bearer-auth'
43
4+ import storeRouter from './routes/store'
5+
56const app = new Hono ( )
67
78const token = Bun . env . BEARER_TOKEN || ""
89
910app . use ( '/api/*' , bearerAuth ( { token } ) )
1011
12+ app . route ( '/api/store' , storeRouter )
13+
1114app . get ( '/' , ( c ) => {
12- connectDB ( )
1315 return c . text ( "Hello world" )
1416} )
1517
16- app . get ( '/api/page' , ( c ) => {
17- return c . json ( { message : 'You are authorized' } )
18- } )
19-
2018export default app
Original file line number Diff line number Diff line change 1+ import { Hono } from 'hono'
2+ import { createStore } from '../controllers/storeController'
3+
4+ const storeRouter = new Hono ( )
5+
6+ // create a store
7+ storeRouter . post ( '/' , ( c ) => createStore ( c ) )
8+
9+ export default storeRouter
You can’t perform that action at this time.
0 commit comments