|
1 |
| -import "dotenv/config"; |
2 |
| -import { Hono } from "hono"; |
3 |
| -import { PrismaClient } from "./generated/prisma/client"; |
4 |
| -import { serve } from "@hono/node-server"; |
| 1 | +import 'dotenv/config' |
| 2 | +import { Hono } from 'hono' |
| 3 | +import { PrismaClient } from './generated/prisma/client' |
| 4 | +import { serve } from '@hono/node-server' |
5 | 5 |
|
6 |
| -const prisma = new PrismaClient(); |
7 |
| -const app = new Hono(); |
| 6 | +const prisma = new PrismaClient() |
| 7 | +const app = new Hono() |
8 | 8 |
|
9 |
| -app.get("/", (c) => { |
| 9 | +app.get('/', (c) => { |
10 | 10 | const html = `
|
11 | 11 | <!DOCTYPE html>
|
12 | 12 | <html>
|
@@ -56,71 +56,71 @@ app.get("/", (c) => {
|
56 | 56 | </script>
|
57 | 57 | </body>
|
58 | 58 | </html>
|
59 |
| - `; |
60 |
| - return c.html(html); |
61 |
| -}); |
| 59 | + ` |
| 60 | + return c.html(html) |
| 61 | +}) |
62 | 62 |
|
63 |
| -app.get("/api", async (c) => { |
64 |
| - return c.json({ up: true }); |
65 |
| -}); |
| 63 | +app.get('/api', async (c) => { |
| 64 | + return c.json({ up: true }) |
| 65 | +}) |
66 | 66 |
|
67 |
| -app.get("/api/seed", async (c) => { |
| 67 | +app.get('/api/seed', async (c) => { |
68 | 68 | try {
|
69 |
| - await prisma.post.deleteMany({}); |
70 |
| - await prisma.user.deleteMany({}); |
| 69 | + await prisma.post.deleteMany({}) |
| 70 | + await prisma.user.deleteMany({}) |
71 | 71 |
|
72 | 72 | const author1 = await prisma.user.create({
|
73 | 73 | data: {
|
74 |
| - |
75 |
| - name: "Jane Doe", |
| 74 | + |
| 75 | + name: 'Jane Doe', |
76 | 76 | posts: {
|
77 | 77 | create: {
|
78 |
| - title: "Comparing Database Types", |
| 78 | + title: 'Comparing Database Types', |
79 | 79 | content:
|
80 |
| - "https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/", |
| 80 | + 'https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/', |
81 | 81 | published: true,
|
82 | 82 | },
|
83 | 83 | },
|
84 | 84 | },
|
85 | 85 | include: { posts: true },
|
86 |
| - }); |
| 86 | + }) |
87 | 87 |
|
88 | 88 | const author2 = await prisma.user.create({
|
89 | 89 | data: {
|
90 |
| - |
91 |
| - name: "John Smith", |
| 90 | + |
| 91 | + name: 'John Smith', |
92 | 92 | posts: {
|
93 | 93 | create: {
|
94 |
| - title: "Getting Started with Prisma", |
95 |
| - content: "https://www.prisma.io/docs/getting-started", |
| 94 | + title: 'Getting Started with Prisma', |
| 95 | + content: 'https://www.prisma.io/docs/getting-started', |
96 | 96 | published: true,
|
97 | 97 | },
|
98 | 98 | },
|
99 | 99 | },
|
100 | 100 | include: { posts: true },
|
101 |
| - }); |
| 101 | + }) |
102 | 102 |
|
103 | 103 | return c.json({
|
104 |
| - message: "Database seeded successfully", |
| 104 | + message: 'Database seeded successfully', |
105 | 105 | authors: [author1, author2],
|
106 |
| - }); |
| 106 | + }) |
107 | 107 | } catch (e) {
|
108 |
| - return c.json({ error: "Failed to seed database" }, 500); |
| 108 | + return c.json({ error: 'Failed to seed database' }, 500) |
109 | 109 | }
|
110 |
| -}); |
| 110 | +}) |
111 | 111 |
|
112 |
| -app.get("/api/feed", async (c) => { |
| 112 | +app.get('/api/feed', async (c) => { |
113 | 113 | const posts = await prisma.post.findMany({
|
114 | 114 | where: { published: true },
|
115 | 115 | include: { author: true },
|
116 |
| - }); |
117 |
| - return c.json(posts); |
118 |
| -}); |
| 116 | + }) |
| 117 | + return c.json(posts) |
| 118 | +}) |
119 | 119 |
|
120 |
| -const port = process.env.PORT ? Number(process.env.PORT) : 3000; |
121 |
| -console.log(`Server is running on port http://localhost:${port}`); |
| 120 | +const port = process.env.PORT ? Number(process.env.PORT) : 3000 |
| 121 | +console.log(`Server is running at http://localhost:${port}`) |
122 | 122 |
|
123 | 123 | serve({
|
124 | 124 | fetch: app.fetch,
|
125 | 125 | port,
|
126 |
| -}); |
| 126 | +}) |
0 commit comments