Ver código fonte

first commit

xiongzhu 1 ano atrás
commit
0fe7b0523b
10 arquivos alterados com 105 adições e 0 exclusões
  1. 10 0
      .gitignore
  2. 6 0
      .prettierrc.json
  3. 8 0
      README.md
  4. 7 0
      bindings.d.ts
  5. 14 0
      package.json
  6. 1 0
      scripts/migration.ts
  7. 12 0
      src/index.ts
  8. 13 0
      src/routes/users-route.ts
  9. 16 0
      tsconfig.json
  10. 18 0
      wrangler.toml

+ 10 - 0
.gitignore

@@ -0,0 +1,10 @@
+node_modules
+dist
+.wrangler
+.dev.vars
+
+# Change them to your taste:
+package-lock.json
+yarn.lock
+pnpm-lock.yaml
+bun.lockb

+ 6 - 0
.prettierrc.json

@@ -0,0 +1,6 @@
+{
+    "tabWidth": 4,
+    "semi": false,
+    "trailingComma": "none",
+    "arrowParens": "avoid"
+}

+ 8 - 0
README.md

@@ -0,0 +1,8 @@
+```
+npm install
+npm run dev
+```
+
+```
+npm run deploy
+```

+ 7 - 0
bindings.d.ts

@@ -0,0 +1,7 @@
+type Environment = {
+    Bindings: {
+        ENV: string
+        DB: D1Database
+    }
+    Variables: {}
+}

+ 14 - 0
package.json

@@ -0,0 +1,14 @@
+{
+  "scripts": {
+    "dev": "wrangler dev src/index.ts",
+    "deploy": "wrangler deploy --minify src/index.ts",
+    "preview": "wrangler preview --watch src/index.ts"
+  },
+  "dependencies": {
+    "hono": "^4.1.3"
+  },
+  "devDependencies": {
+    "@cloudflare/workers-types": "^4.20240208.0",
+    "wrangler": "^3.32.0"
+  }
+}

+ 1 - 0
scripts/migration.ts

@@ -0,0 +1 @@
+import { env, getRuntimeKey } from 'hono/adapter'

+ 12 - 0
src/index.ts

@@ -0,0 +1,12 @@
+import { Hono } from "hono"
+import UserRoute from "./routes/users-route"
+
+const app = new Hono<Environment>()
+
+app.get("/:id", c => {
+    c.req.param('id')
+    return c.text("Hello World!")
+})
+app.route("/users", UserRoute)
+
+export default app

+ 13 - 0
src/routes/users-route.ts

@@ -0,0 +1,13 @@
+import { Hono } from "hono"
+
+const route = new Hono<Environment>()
+
+route.get("/", c => {
+    return c.text("Hello User!")
+})
+
+route.post("/", c => {
+    return c.text("User created!")
+})
+
+export default route

+ 16 - 0
tsconfig.json

@@ -0,0 +1,16 @@
+{
+  "compilerOptions": {
+    "target": "ESNext",
+    "module": "ESNext",
+    "moduleResolution": "Bundler",
+    "strict": true,
+    "lib": [
+      "ESNext"
+    ],
+    "types": [
+      "@cloudflare/workers-types"
+    ],
+    "jsx": "react-jsx",
+    "jsxImportSource": "hono/jsx"
+  },
+}

+ 18 - 0
wrangler.toml

@@ -0,0 +1,18 @@
+name = "my-app"
+compatibility_date = "2023-12-01"
+
+# [vars]
+# MY_VAR = "my-variable"
+
+# [[kv_namespaces]]
+# binding = "MY_KV_NAMESPACE"
+# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+
+# [[r2_buckets]]
+# binding = "MY_BUCKET"
+# bucket_name = "my-bucket"
+
+[[d1_databases]]
+binding = "DB"
+database_name = "prod-d1-tutorial"
+database_id = "c6528cc6-196d-4349-ae5b-5d74362ccc60"