mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-05 11:38:36 +09:00
## Description 1. Add 404 instead of redirect 2. Fix vercel/remix upload ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio-builder/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { renderToString } from "react-dom/server";
|
|
import { RemixServer } from "@remix-run/react";
|
|
import type { EntryContext } from "@remix-run/node";
|
|
import { flushCss } from "@webstudio-is/design-system";
|
|
import { renderHeadToString } from "remix-island";
|
|
import { Head } from "./root";
|
|
import { links } from "~/routes/vercel-deploy-workaround";
|
|
|
|
export const handleRequest = (
|
|
request: Request,
|
|
responseStatusCode: number,
|
|
responseHeaders: Headers,
|
|
remixContext: EntryContext
|
|
) => {
|
|
const markup = renderToString(
|
|
<RemixServer context={remixContext} url={request.url} />
|
|
);
|
|
|
|
const head = renderHeadToString({ request, remixContext, Head });
|
|
|
|
responseHeaders.set("Content-Type", "text/html");
|
|
responseHeaders.set("Accept-CH", "Sec-CH-Prefers-Color-Scheme");
|
|
|
|
// data-builder="true" to distinguish between builder and canvas at the entry.client.tsx
|
|
// inject fonts and base body styles here instead of `export links = ` to avoid FOUC
|
|
const body = `
|
|
<!DOCTYPE html>
|
|
<html lang="en" data-builder="true">
|
|
<head>
|
|
<meta charSet="utf-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
${links()
|
|
.map((link) =>
|
|
"href" in link
|
|
? `<link rel="${link.rel}" href="${link.href}" />`
|
|
: ""
|
|
)
|
|
.join("\n")}
|
|
${head}
|
|
<style id="stitches">${flushCss()}</style>
|
|
</head>
|
|
<body>
|
|
<div id="root">${markup}</div>
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
return new Response(body, {
|
|
status: responseStatusCode,
|
|
headers: responseHeaders,
|
|
});
|
|
};
|