From a1be2840b6b1ea8a15d546efcdd89d800aec8e7f Mon Sep 17 00:00:00 2001 From: casulit Date: Thu, 24 Oct 2024 06:24:14 +0800 Subject: [PATCH] refactor(server): Update Hono import and add CORS middleware --- deno.json | 2 +- deno.lock | 13 ++++++------- server.ts | 7 ++++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/deno.json b/deno.json index 8fb6230..1ca0217 100644 --- a/deno.json +++ b/deno.json @@ -4,8 +4,8 @@ "imports": { "@clerk/backend": "npm:@clerk/backend@^1.13.9", "@hono/clerk-auth": "npm:@hono/clerk-auth@^2.0.0", - "@hono/hono": "jsr:@hono/hono@^4.6.5", "@std/dotenv": "jsr:@std/dotenv@^0.225.2", + "hono": "npm:hono@^4.6.6", "postgres": "https://deno.land/x/postgres@v0.19.3/mod.ts", "zod": "npm:zod@^3.23.8" }, diff --git a/deno.lock b/deno.lock index ecd17d6..5ff753a 100644 --- a/deno.lock +++ b/deno.lock @@ -1,18 +1,14 @@ { "version": "4", "specifiers": { - "jsr:@hono/hono@*": "4.6.5", - "jsr:@hono/hono@^4.6.5": "4.6.5", "jsr:@std/dotenv@*": "0.225.2", "jsr:@std/dotenv@~0.225.2": "0.225.2", "npm:@clerk/backend@^1.13.9": "1.13.9", "npm:@hono/clerk-auth@2": "2.0.0_@clerk+backend@1.13.9_hono@4.6.4", + "npm:hono@^4.6.6": "4.6.6", "npm:zod@^3.23.8": "3.23.8" }, "jsr": { - "@hono/hono@4.6.5": { - "integrity": "68efe4a0ab7c4fb082cb71aa894a25e1c6cfad6d124dc943471e6758a7a1bdee" - }, "@std/dotenv@0.225.2": { "integrity": "e2025dce4de6c7bca21dece8baddd4262b09d5187217e231b033e088e0c4dd23" } @@ -48,7 +44,7 @@ "integrity": "sha512-ad+U8jDlBPgXBTv8BRnPrSFC/uX8U0ojiCR77I3WWHm5I9L3/bHsZpQ2lgvLTV3YbJyVmAdKJArEAQiPjodGdA==", "dependencies": [ "@clerk/backend", - "hono" + "hono@4.6.4" ] }, "client-only@0.0.1": { @@ -73,6 +69,9 @@ "hono@4.6.4": { "integrity": "sha512-T5WqBkTOcIQblqBKB5mpzaH/A+dSpvVe938xZJCHOmOuYfF7DSwE/9/10+BMvwSPq9N/f6LiQ38HxrZSQOsXKw==" }, + "hono@4.6.6": { + "integrity": "sha512-euUj5qwvtkG+p38GFs0LYacwaoS2hYRAGn9ysAggiwT2QBcPnT1XYUCW3hatW4C1KzAXTYuQ08BlVDJtAGuhlg==" + }, "js-cookie@3.0.5": { "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==" }, @@ -276,10 +275,10 @@ }, "workspace": { "dependencies": [ - "jsr:@hono/hono@^4.6.5", "jsr:@std/dotenv@~0.225.2", "npm:@clerk/backend@^1.13.9", "npm:@hono/clerk-auth@2", + "npm:hono@^4.6.6", "npm:zod@^3.23.8" ] } diff --git a/server.ts b/server.ts index b76c067..b86793e 100644 --- a/server.ts +++ b/server.ts @@ -1,5 +1,6 @@ import "jsr:@std/dotenv/load"; -import { type Context, Hono } from "jsr:@hono/hono"; +import { type Context, Hono } from "npm:hono"; +import { cors } from "npm:hono/cors"; import { dbPool } from "./config/postgres.ts"; import { getKvInstance, listenQueue, sendMessage } from "./config/deno-kv.ts"; @@ -7,6 +8,10 @@ import { getKvInstance, listenQueue, sendMessage } from "./config/deno-kv.ts"; const app = new Hono(); const kv = await getKvInstance(); +app.use("*", cors({ + origin: "*", +})); + app.get("/api/properties", async (c: Context) => { using client = await dbPool.connect(); const query = c.req.query() as unknown as {