utils/templates.js 5.7 K raw
1
export const honoRpcTemplate = `import { Hono } from 'hono'
2
import { cors } from 'hono/cors'
3
import type { ApiResponse } from 'shared/dist'
4
5
const app = new Hono()
6
7
app.use(cors())
8
9
app.get('/', (c) => {
10
  return c.text('Hello Hono!')
11
})
12
13
app.get('/hello', async (c) => {
14
15
  const data: ApiResponse = {
16
    message: "Hello BHVR!",
17
    success: true
18
  }
19
20
  return c.json(data, { status: 200 })
21
})
22
23
export type AppType = typeof app
24
export default app`;
25
26
export const tailwindTemplate = `import { useState } from 'react'
27
import beaver from './assets/beaver.svg'
28
import type { AppType } from 'server'
29
import { hc } from 'hono/client'
30
31
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
32
33
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
34
35
//@ts-ignore
36
const client = hc<AppType>(SERVER_URL);
37
38
function App() {
39
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
40
41
  async function sendRequest() {
42
    try {
43
      const res = await client.hello.$get()
44
      if (!res.ok) {
45
        console.log("Error fetching data")
46
        return
47
      }
48
      const data = await res.json()
49
      setData(data)
50
    } catch (error) {
51
      console.log(error)
52
    }
53
  }
54
55
  return (
56
    <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen">
57
      <a href="https://github.com/stevedylandev/bhvr" target="_blank">
58
        <img
59
          src={beaver}
60
          className="w-16 h-16 cursor-pointer"
61
          alt="beaver logo"
62
        />
63
      </a>
64
      <h1 className="text-5xl font-black">bhvr</h1>
65
      <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2>
66
      <p>A typesafe fullstack monorepo</p>
67
      <div className='flex items-center gap-4'>
68
        <button
69
          onClick={sendRequest}
70
          className="bg-black text-white px-2.5 py-1.5 rounded-md"
71
        >
72
          Call API
73
        </button>
74
        <a target='_blank' href="https://bhvr.dev" className='border-1 border-black text-black px-2.5 py-1.5 rounded-md'>
75
          Docs
76
        </a>
77
      </div>
78
        {data && (
79
          <pre className="bg-gray-100 p-4 rounded-md">
80
            <code>
81
            Message: {data.message} <br />
82
            Success: {data.success.toString()}
83
            </code>
84
          </pre>
85
        )}
86
    </div>
87
  )
88
}
89
90
export default App`;
91
92
export const shadcnTemplate = `import { useState } from 'react'
93
import beaver from './assets/beaver.svg'
94
import { Button } from './components/ui/button'
95
import type { AppType } from 'server'
96
import { hc } from 'hono/client'
97
98
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
99
100
//@ts-ignore
101
const client = hc<AppType>(SERVER_URL);
102
103
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
104
105
function App() {
106
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
107
108
  async function sendRequest() {
109
    try {
110
      const res = await client.hello.$get()
111
      if (!res.ok) {
112
        console.log("Error fetching data")
113
        return
114
      }
115
      const data = await res.json()
116
      setData(data)
117
    } catch (error) {
118
      console.log(error)
119
    }
120
  }
121
122
  return (
123
    <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen">
124
      <a href="https://github.com/stevedylandev/bhvr" target="_blank">
125
        <img
126
          src={beaver}
127
          className="w-16 h-16 cursor-pointer"
128
          alt="beaver logo"
129
        />
130
      </a>
131
      <h1 className="text-5xl font-black">bhvr</h1>
132
      <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2>
133
      <p>A typesafe fullstack monorepo</p>
134
      <div className='flex items-center gap-4'>
135
        <Button
136
          onClick={sendRequest}
137
        >
138
          Call API
139
        </Button>
140
        <Button
141
          variant='secondary'
142
          asChild
143
        >
144
          <a target='_blank' href="https://bhvr.dev">
145
          Docs
146
          </a>
147
        </Button>
148
      </div>
149
        {data && (
150
          <pre className="bg-gray-100 p-4 rounded-md">
151
            <code>
152
            Message: {data.message} <br />
153
            Success: {data.success.toString()}
154
            </code>
155
          </pre>
156
        )}
157
    </div>
158
  )
159
}
160
161
export default App`;
162
163
export const defaultTemplate = `import { useState } from 'react'
164
import beaver from './assets/beaver.svg'
165
import type { AppType } from 'server'
166
import { hc } from 'hono/client'
167
import './App.css'
168
169
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
170
171
//@ts-ignore
172
const client = hc<AppType>(SERVER_URL);
173
174
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
175
176
function App() {
177
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
178
179
  async function sendRequest() {
180
    try {
181
      const res = await client.hello.$get()
182
      if (!res.ok) {
183
        console.log("Error fetching data")
184
        return
185
      }
186
      const data = await res.json()
187
      setData(data)
188
    } catch (error) {
189
      console.log(error)
190
    }
191
  }
192
193
  return (
194
    <>
195
      <div>
196
        <a href="https://github.com/stevedylandev/bhvr" target="_blank">
197
          <img src={beaver} className="logo" alt="beaver logo" />
198
        </a>
199
      </div>
200
      <h1>bhvr</h1>
201
      <h2>Bun + Hono + Vite + React</h2>
202
      <p>A typesafe fullstack monorepo</p>
203
      <div className="card">
204
        <div className='button-container'>
205
          <button onClick={sendRequest}>
206
            Call API
207
          </button>
208
          <a className='docs-link' target='_blank' href="https://bhvr.dev">Docs</a>
209
        </div>
210
        {data && (
211
          <pre className='response'>
212
            <code>
213
            Message: {data.message} <br />
214
            Success: {data.success.toString()}
215
            </code>
216
          </pre>
217
        )}
218
      </div>
219
    </>
220
  )
221
}
222
223
export default App`;