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