Bootstraps from Shopify's official shopify-app-template-remix (cloned directly rather than via `shopify app init`, which requires an interactive Partner login unavailable in this session): - Prisma (SQLite dev / Postgres-ready) with baseline Session model + migration - Vitest configured for unit tests, Playwright configured for E2E - Redis client + BullMQ worker skeleton (app/lib/redis.server.ts, jobs/worker.ts) - shopify.app.toml: minimal scopes, GDPR + orders webhooks wired (stub handlers), app proxy config for the future storefront widget - Stripped template-repo-only meta files (CLA, issue templates, demo product page) and replaced CI with a lint+typecheck+test workflow - Bumped @shopify/shopify-app-session-storage-prisma to resolve a duplicate @shopify/shopify-api install that broke typecheck - Dropped the Jest-only ESLint config (template default) since the project standardizes on Vitest per IMPLEMENTATION_PLAN.md Verified: npm install, lint, typecheck, unit tests, prisma migrate dev, and npm run build all pass on Node 22 LTS. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { PassThrough } from "stream";
|
|
import { renderToPipeableStream } from "react-dom/server";
|
|
import { RemixServer } from "@remix-run/react";
|
|
import {
|
|
createReadableStreamFromReadable,
|
|
type EntryContext,
|
|
} from "@remix-run/node";
|
|
import { isbot } from "isbot";
|
|
import { addDocumentResponseHeaders } from "./shopify.server";
|
|
|
|
export const streamTimeout = 5000;
|
|
|
|
export default async function handleRequest(
|
|
request: Request,
|
|
responseStatusCode: number,
|
|
responseHeaders: Headers,
|
|
remixContext: EntryContext
|
|
) {
|
|
addDocumentResponseHeaders(request, responseHeaders);
|
|
const userAgent = request.headers.get("user-agent");
|
|
const callbackName = isbot(userAgent ?? '')
|
|
? "onAllReady"
|
|
: "onShellReady";
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const { pipe, abort } = renderToPipeableStream(
|
|
<RemixServer
|
|
context={remixContext}
|
|
url={request.url}
|
|
/>,
|
|
{
|
|
[callbackName]: () => {
|
|
const body = new PassThrough();
|
|
const stream = createReadableStreamFromReadable(body);
|
|
|
|
responseHeaders.set("Content-Type", "text/html");
|
|
resolve(
|
|
new Response(stream, {
|
|
headers: responseHeaders,
|
|
status: responseStatusCode,
|
|
})
|
|
);
|
|
pipe(body);
|
|
},
|
|
onShellError(error) {
|
|
reject(error);
|
|
},
|
|
onError(error) {
|
|
responseStatusCode = 500;
|
|
console.error(error);
|
|
},
|
|
}
|
|
);
|
|
|
|
// Automatically timeout the React renderer after 6 seconds, which ensures
|
|
// React has enough time to flush down the rejected boundary contents
|
|
setTimeout(abort, streamTimeout + 1000);
|
|
});
|
|
}
|