bini-router 1.0.30 → 1.0.31

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/dist/index.cjs CHANGED
@@ -1349,21 +1349,37 @@ function buildProductionEntry(srcApiDir, platform, enableCors, basePath = "") {
1349
1349
  lines.push(...[
1350
1350
  `// Serve static files from dist (must come AFTER API routes)`,
1351
1351
  `app.get('/*', async (c) => {`,
1352
+ ` // Skip API routes - let them be handled first`,
1353
+ ` if (c.req.path.startsWith('/api/')) {`,
1354
+ ` return c.text('API route not found', 404);`,
1355
+ ` }`,
1356
+ ` `,
1357
+ ` const filePath = c.req.path === '/' ? '/index.html' : c.req.path;`,
1358
+ ` `,
1352
1359
  ` try {`,
1353
- ` const path = c.req.path === '/' ? '/index.html' : c.req.path;`,
1354
- ` const file = await Deno.readFile(\`./dist\${path}\`);`,
1355
- ` const ext = path.split('.').pop();`,
1356
- ` const contentType = ext === 'html' ? 'text/html' :`,
1357
- ` ext === 'css' ? 'text/css' :`,
1358
- ` ext === 'js' ? 'application/javascript' :`,
1359
- ` 'text/plain';`,
1360
- ` return new Response(file, { headers: { 'Content-Type': contentType } });`,
1360
+ ` const file = await Deno.readFile(\`./dist\${filePath}\`);`,
1361
+ ` const ext = filePath.split('.').pop();`,
1362
+ ` const contentType = `,
1363
+ ` ext === 'html' ? 'text/html' :`,
1364
+ ` ext === 'css' ? 'text/css' :`,
1365
+ ` ext === 'js' ? 'application/javascript' :`,
1366
+ ` ext === 'json' ? 'application/json' :`,
1367
+ ` ext === 'png' ? 'image/png' :`,
1368
+ ` ext === 'jpg' || ext === 'jpeg' ? 'image/jpeg' :`,
1369
+ ` 'text/plain';`,
1370
+ ` `,
1371
+ ` return new Response(file, {`,
1372
+ ` headers: { 'Content-Type': contentType }`,
1373
+ ` });`,
1361
1374
  ` } catch {`,
1375
+ ` // SPA fallback`,
1362
1376
  ` try {`,
1363
1377
  ` const indexHtml = await Deno.readFile('./dist/index.html');`,
1364
- ` return new Response(indexHtml, { headers: { 'Content-Type': 'text/html' } });`,
1378
+ ` return new Response(indexHtml, {`,
1379
+ ` headers: { 'Content-Type': 'text/html' }`,
1380
+ ` });`,
1365
1381
  ` } catch {`,
1366
- ` return new Response('File not found', { status: 404 });`,
1382
+ ` return c.text('File not found', 404);`,
1367
1383
  ` }`,
1368
1384
  ` }`,
1369
1385
  `});`,