Skip to content

Commit

Permalink
fix(api): deploy using next env
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Jun 8, 2024
1 parent 249aacd commit e556159
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 9,435 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public-hoist-pattern[]=*prisma*
public-hoist-pattern[]=*clerk*
8 changes: 0 additions & 8 deletions apps/api/api/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ const app = new Hono({ strict: true })
.route('/api/v1', appV1)

export * from './v1/validation'
export * from './prisma/generated/zod'
// export * from './prisma/generated/zod'
export { app }
export type AppType = typeof app
8 changes: 5 additions & 3 deletions apps/api/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// import { Pool } from '@neondatabase/serverless'
// import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'

// biome-ignore lint/style/useConst: <explanation>
let prisma: PrismaClient
// const neon = new Pool({ connectionString: process.env.POSTGRES_PRISMA_URL })
// const adapter = new PrismaNeon(neon)

prisma = new PrismaClient()
const prisma = new PrismaClient()

// if (process.env.NODE_ENV === 'production') {
// prisma = new PrismaClient()
Expand Down
5 changes: 5 additions & 0 deletions apps/api/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
6 changes: 6 additions & 0 deletions apps/api/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}

module.exports = nextConfig
21 changes: 16 additions & 5 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@
"license": "GPL-3.0",
"private": true,
"scripts": {
"start": "vercel dev",
"deploy": "vercel",
"dev": "next dev",
"build": "next build",
"start": "next start",
"prisma:migrate": "prisma migrate dev",
"prisma:generate": "prisma generate",
"prisma:reset": "prisma migrate reset --force",
"prisma:studio": "prisma studio"
"prisma:studio": "prisma studio",
"postinstall": "prisma generate"
},
"dependencies": {
"@clerk/backend": "^1.2.2",
"@hono/clerk-auth": "^2.0.0",
"@hono/node-server": "^1.11.2",
"@hono/zod-validator": "^0.2.2",
"@neondatabase/serverless": "^0.9.3",
"@prisma/adapter-neon": "^5.15.0",
"@prisma/client": "^5.15.0",
"dayjs": "^1.11.11",
"hono": "^4.4.3",
"hono": "^4.4.4",
"next": "^14.2.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "18.11.18",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"prisma": "^5.15.0",
"vercel": "^34.2.5",
"typescript": "^5.4.5",
"zod-prisma-types": "^3.1.8"
}
}
5 changes: 5 additions & 0 deletions apps/api/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { AppProps } from 'next/app'

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
13 changes: 13 additions & 0 deletions apps/api/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
return (
<Html lang='en'>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
11 changes: 11 additions & 0 deletions apps/api/pages/api/[...route].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { handle } from '@hono/node-server/vercel'
import type { PageConfig } from 'next'
import { app } from '../..'

export const config: PageConfig = {
api: {
bodyParser: false,
},
}

export default handle(app)
18 changes: 18 additions & 0 deletions apps/api/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect, useState } from 'react'

export default function Home() {
const [message, setMessage] = useState()

useEffect(() => {
const fetchData = async () => {
const res = await fetch('/api/hello')
const { message } = await res.json()
setMessage(message)
}
fetchData()
}, [])

if (!message) return <p>Loading...</p>

return <p>{message}</p>
}
Loading

0 comments on commit e556159

Please sign in to comment.