@checkstack/backend 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @checkstack/backend
2
2
 
3
+ ## 0.6.4
4
+
5
+ ### Patch Changes
6
+
7
+ - a713e0f: Fix static file Content-Length header stripped by Hono middleware
8
+
9
+ Hono's CORS middleware wraps raw `Response` objects and strips Bun's auto-generated headers. Switched to using `c.body()` + `c.header()` so Content-Type and Content-Length survive the middleware pipeline. Extracted a shared `serveFile` helper for all static file routes.
10
+
3
11
  ## 0.6.3
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/backend",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "checkstack": {
5
5
  "type": "backend"
6
6
  },
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Server } from "bun";
2
- import { Hono } from "hono";
2
+ import { type Context, Hono } from "hono";
3
3
  import { PluginManager } from "./plugin-manager";
4
4
  import { logger } from "hono/logger";
5
5
  import { migrate } from "drizzle-orm/node-postgres/migrator";
@@ -174,6 +174,13 @@ app.get("/.well-known/jwks.json", async (c) => {
174
174
  const frontendDistPath = process.env.CHECKSTACK_FRONTEND_DIST;
175
175
  if (frontendDistPath && fs.existsSync(frontendDistPath)) {
176
176
  rootLogger.info(`📦 Serving frontend from: ${frontendDistPath}`);
177
+ /** Serve a static file via Hono's context to preserve headers through middleware. */
178
+ const serveFile = async (c: Context, filePath: string) => {
179
+ const file = Bun.file(filePath);
180
+ c.header("Content-Type", file.type);
181
+ c.header("Content-Length", String(file.size));
182
+ return c.body(file.stream());
183
+ };
177
184
 
178
185
  // Serve static assets (JS, CSS, images, etc.)
179
186
  app.get("/assets/*", async (c) => {
@@ -181,10 +188,7 @@ if (frontendDistPath && fs.existsSync(frontendDistPath)) {
181
188
  const filePath = path.join(frontendDistPath, "assets", assetPath);
182
189
 
183
190
  if (fs.existsSync(filePath)) {
184
- const file = Bun.file(filePath);
185
- return new Response(file, {
186
- headers: { "Content-Type": file.type },
187
- });
191
+ return serveFile(c, filePath);
188
192
  }
189
193
  return c.notFound();
190
194
  });
@@ -195,10 +199,7 @@ if (frontendDistPath && fs.existsSync(frontendDistPath)) {
195
199
  const filePath = path.join(frontendDistPath, "vendor", vendorPath);
196
200
 
197
201
  if (fs.existsSync(filePath)) {
198
- const file = Bun.file(filePath);
199
- return new Response(file, {
200
- headers: { "Content-Type": file.type },
201
- });
202
+ return serveFile(c, filePath);
202
203
  }
203
204
  return c.notFound();
204
205
  });
@@ -218,20 +219,14 @@ if (frontendDistPath && fs.existsSync(frontendDistPath)) {
218
219
  const staticFilePath = path.join(frontendDistPath, reqPath);
219
220
  // Only serve if it's a file (not a directory) and exists
220
221
  if (fs.existsSync(staticFilePath) && fs.statSync(staticFilePath).isFile()) {
221
- const file = Bun.file(staticFilePath);
222
- return new Response(file, {
223
- headers: { "Content-Type": file.type },
224
- });
222
+ return serveFile(c, staticFilePath);
225
223
  }
226
224
  }
227
225
 
228
226
  // SPA fallback: serve index.html for all remaining non-API routes
229
227
  const indexPath = path.join(frontendDistPath, "index.html");
230
228
  if (fs.existsSync(indexPath)) {
231
- const file = Bun.file(indexPath);
232
- return new Response(file, {
233
- headers: { "Content-Type": "text/html" },
234
- });
229
+ return serveFile(c, indexPath);
235
230
  }
236
231
  return c.notFound();
237
232
  });