chore: Added some styling to single origin deployment 434059d8
Steve · 2025-05-25 00:00 1 file(s) · +17 −17
docs/pages/deployment/single-origin.mdx +17 −17
50 50
```typescript
51 51
import { Hono } from "hono";
52 52
import { cors } from "hono/cors";
53 -
import { serveStatic } from "hono/bun";
53 +
import { serveStatic } from "hono/bun"; // [!code ++]
54 54
import type { ApiResponse } from "shared/dist";
55 55
56 56
const app = new Hono();
77 77
// app.post('/api/data', ...)
78 78
79 79
// Serve static files for everything else
80 -
app.use("*", serveStatic({ root: "./static" }));
80 +
app.use("*", serveStatic({ root: "./static" })); // [!code ++]
81 81
82 -
app.get("*", async (c, next) => {
83 -
  return serveStatic({ root: "./static", path: "index.html" })(c, next);
84 -
});
82 +
app.get("*", async (c, next) => { // [!code ++]
83 +
  return serveStatic({ root: "./static", path: "index.html" })(c, next); // [!code ++]
84 +
}); // [!code ++]
85 85
86 86
const port = parseInt(process.env.PORT || "3000");
87 87
109 109
  async function sendRequest() {
110 110
    try {
111 111
      // Use relative path - works in both dev and production
112 -
      const req = await fetch("/api/hello");
112 +
      const req = await fetch("/api/hello"); // [!code hl]
113 113
      const res: ApiResponse = await req.json();
114 114
      setData(res);
115 115
    } catch (error) {
164 164
      "@shared": path.resolve(__dirname, "../shared/src"),
165 165
    },
166 166
  },
167 -
  server: {
168 -
    proxy: {
169 -
      "/api": {
170 -
        target: "http://localhost:3000",
171 -
        changeOrigin: true,
172 -
      },
173 -
    },
174 -
  },
167 +
  server: { // [!code ++]
168 +
    proxy: { // [!code ++]
169 +
      "/api": { // [!code ++]
170 +
        target: "http://localhost:3000", // [!code ++]
171 +
        changeOrigin: true, // [!code ++]
172 +
      }, // [!code ++]
173 +
    }, // [!code ++]
174 +
  }, // [!code ++]
175 175
});
176 176
```
177 177
190 190
    "build:shared": "cd shared && bun run build",
191 191
    "build:server": "cd server && bun run build",
192 192
    "build": "bun run build:shared && bun run build:client",
193 -
    "build:single": "bun run build && bun run copy:static && bun run build:server",
194 -
    "copy:static": "rm -rf server/static && cp -r client/dist server/static",
195 -
    "start:single": "cd server && bun run dist/index.js",
193 +
    "build:single": "bun run build && bun run copy:static && bun run build:server", // [!code ++]
194 +
    "copy:static": "rm -rf server/static && cp -r client/dist server/static", // [!code ++]
195 +
    "start:single": "cd server && bun run dist/index.js", // [!code ++]
196 196
    "postinstall": "bun run build:shared && bun run build:server"
197 197
  }
198 198
}