Template
Ports nextjs-templates/shopify-storefront to Vite, TanStack Router/Query, Tailwind v4 and Hono, without the AI store assistant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
// Production entry: the API plus the static client build, with an SPA fallback
|
|
// so deep links like /products/:handle load index.html.
|
|
import { readFile } from 'node:fs/promises';
|
|
import { Hono } from 'hono';
|
|
import { serve } from '@hono/node-server';
|
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
import api from './app';
|
|
|
|
const CLIENT_DIR = './dist/client';
|
|
const indexHtml = await readFile(`${CLIENT_DIR}/index.html`, 'utf8');
|
|
|
|
const app = new Hono();
|
|
|
|
app.route('/', api);
|
|
// Unknown API paths stay JSON 404s rather than falling through to the SPA.
|
|
app.all('/api/*', (c) => c.json({ error: 'Not found' }, 404));
|
|
|
|
// Hashed build assets never change, so let browsers keep them.
|
|
app.use('/assets/*', async (c, next) => {
|
|
await next();
|
|
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
|
});
|
|
app.use('*', serveStatic({ root: CLIENT_DIR }));
|
|
app.get('*', (c) => c.html(indexHtml));
|
|
|
|
const port = Number(process.env.PORT) || 3000;
|
|
|
|
serve({ fetch: app.fetch, port }, (info) => {
|
|
console.log(`Storefront listening on http://localhost:${info.port}`);
|
|
});
|