Skip to content

Commit

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

This file was deleted.

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>
}
30 changes: 24 additions & 6 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"baseUrl": "./",
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
2 changes: 1 addition & 1 deletion apps/api/v1/middlewares/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { clerkMiddleware, getAuth } from '@hono/clerk-auth'
import type { User } from '@prisma/client'
import type { Context } from 'hono'
import { createMiddleware } from 'hono/factory'
import { HTTPException } from 'hono/http-exception'
import type { User } from '../../prisma/generated/zod'
import { findUserById } from '../services/user.service'

declare module 'hono' {
Expand Down
6 changes: 3 additions & 3 deletions apps/api/v1/routes/budgets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zValidator } from '@hono/zod-validator'
import { BudgetUserPermission } from '@prisma/client'
import { Hono } from 'hono'
import { z } from 'zod'
import { BudgetUserPermissionSchema } from '../../prisma/generated/zod'
import { getAuthUser, getAuthUserStrict } from '../middlewares/auth'
import {
canUserDeleteBudgetInvitation,
Expand Down Expand Up @@ -49,7 +49,7 @@ const router = new Hono()
zValidator(
'query',
z.object({
permission: BudgetUserPermissionSchema.optional(),
permission: z.nativeEnum(BudgetUserPermission).optional(),
}),
),
async (c) => {
Expand Down Expand Up @@ -171,7 +171,7 @@ const router = new Hono()
'json',
z.object({
email: z.string().email(),
permission: BudgetUserPermissionSchema.optional(),
permission: z.nativeEnum(BudgetUserPermission).optional(),
}),
),
async (c) => {
Expand Down
13 changes: 5 additions & 8 deletions apps/api/v1/validation/budget.zod.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { BudgetPeriodType, BudgetType } from '@prisma/client'
import { z } from 'zod'
import {
BudgetPeriodTypeSchema,
BudgetTypeSchema,
} from '../../prisma/generated/zod'

export const zCreateBudget = z.object({
name: z.string(),
description: z.string().optional(),
preferredCurrency: z.string(),
type: BudgetTypeSchema,
type: z.nativeEnum(BudgetType),
inviteeEmails: z.array(z.string().email()).optional(),
period: z.object({
type: BudgetPeriodTypeSchema,
type: z.nativeEnum(BudgetPeriodType),
amount: z.number().min(0),
startDate: z.date().optional(),
endDate: z.date().optional(),
Expand All @@ -23,9 +20,9 @@ export const zUpdateBudget = z.object({
name: z.string().optional(),
description: z.string().optional(),
preferredCurrency: z.string().optional(),
type: BudgetTypeSchema.optional(),
type: z.nativeEnum(BudgetType).optional(),
period: z.object({
type: BudgetPeriodTypeSchema.optional(),
type: z.nativeEnum(BudgetPeriodType).optional(),
amount: z.number().min(0).optional(),
startDate: z.date().optional(),
endDate: z.date().optional(),
Expand Down
13 changes: 0 additions & 13 deletions apps/api/vercel.json

This file was deleted.

Loading

0 comments on commit 5cb59f0

Please sign in to comment.