1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import { serve } from "@hono/node-server"; import { Hono } from "hono"; import { cors } from "hono/cors"; import { proxy } from "hono/proxy"; import { fakerZH_CN } from "@faker-js/faker";
const app = new Hono();
app.use(cors());
app.get("/api/user", (c) => { return c.json({ data: { name: fakerZH_CN.person.fullName(), age: fakerZH_CN.person.sex() }, code: 200, message: 'success' }) });
app.all("*", async (c) => { const targetUrl = new URL(c.req.url); targetUrl.host = "localhost:3000";
return proxy(targetUrl, c.req); });
serve( { fetch: app.fetch, port: 3001, }, (info) => { console.log(`Server is running on http://localhost:${info.port}`); } );
|