webstudio 0.0.0-021f2d4
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/LICENSE +661 -0
- package/README.md +145 -0
- package/bin.js +5 -0
- package/lib/cli.js +6578 -0
- package/package.json +88 -0
- package/templates/cloudflare/WS_CF_README.md +48 -0
- package/templates/cloudflare/functions/[[path]].ts +9 -0
- package/templates/cloudflare/load-context.ts +9 -0
- package/templates/cloudflare/package.json +22 -0
- package/templates/cloudflare/tsconfig.json +18 -0
- package/templates/cloudflare/vite.config.ts +21 -0
- package/templates/cloudflare/worker-configuration.d.ts +3 -0
- package/templates/cloudflare/wrangler.toml +55 -0
- package/templates/defaults/app/constants.mjs +12 -0
- package/templates/defaults/app/extension.ts +16 -0
- package/templates/defaults/app/root.tsx +35 -0
- package/templates/defaults/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/defaults/app/route-templates/html.tsx +297 -0
- package/templates/defaults/app/route-templates/redirect.tsx +6 -0
- package/templates/defaults/app/route-templates/xml.tsx +85 -0
- package/templates/defaults/app/routes/[robots.txt].tsx +24 -0
- package/templates/defaults/package.json +35 -0
- package/templates/defaults/public/favicon.ico +0 -0
- package/templates/defaults/tsconfig.json +22 -0
- package/templates/defaults/vite.config.ts +16 -0
- package/templates/internal/package.json +11 -0
- package/templates/internal/tsconfig.json +5 -0
- package/templates/netlify-edge-functions/app/constants.mjs +29 -0
- package/templates/netlify-edge-functions/app/entry.server.tsx +21 -0
- package/templates/netlify-edge-functions/netlify.toml +16 -0
- package/templates/netlify-edge-functions/package.json +9 -0
- package/templates/netlify-edge-functions/vite.config.ts +18 -0
- package/templates/netlify-functions/app/constants.mjs +29 -0
- package/templates/netlify-functions/app/entry.server.tsx +1 -0
- package/templates/netlify-functions/netlify.toml +16 -0
- package/templates/netlify-functions/package.json +9 -0
- package/templates/netlify-functions/vite.config.ts +18 -0
- package/templates/react-router/app/extension.ts +13 -0
- package/templates/react-router/app/root.tsx +35 -0
- package/templates/react-router/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/react-router/app/route-templates/html.tsx +295 -0
- package/templates/react-router/app/route-templates/redirect.tsx +6 -0
- package/templates/react-router/app/route-templates/xml.tsx +85 -0
- package/templates/react-router/app/routes/[robots.txt].tsx +24 -0
- package/templates/react-router/app/routes.ts +4 -0
- package/templates/react-router/package.json +36 -0
- package/templates/react-router/public/favicon.ico +0 -0
- package/templates/react-router/tsconfig.json +18 -0
- package/templates/react-router/vite.config.ts +6 -0
- package/templates/react-router-docker/.dockerignore +4 -0
- package/templates/react-router-docker/Dockerfile +19 -0
- package/templates/react-router-docker/app/constants.mjs +18 -0
- package/templates/react-router-docker/app/routes/[_image].$.ts +24 -0
- package/templates/react-router-docker/package.json +7 -0
- package/templates/react-router-netlify/app/constants.mjs +29 -0
- package/templates/react-router-netlify/netlify.toml +6 -0
- package/templates/react-router-netlify/package.json +9 -0
- package/templates/react-router-netlify/vite.config.ts +7 -0
- package/templates/saas-helpers/package.json +6 -0
- package/templates/saas-helpers/tsconfig.json +18 -0
- package/templates/ssg/app/constants.mjs +13 -0
- package/templates/ssg/app/route-templates/html/+Head.tsx +92 -0
- package/templates/ssg/app/route-templates/html/+Page.tsx +21 -0
- package/templates/ssg/app/route-templates/html/+data.ts +37 -0
- package/templates/ssg/package.json +31 -0
- package/templates/ssg/pages/+config.ts +12 -0
- package/templates/ssg/public/favicon.ico +0 -0
- package/templates/ssg/renderer/+onRenderClient.tsx +30 -0
- package/templates/ssg/renderer/+onRenderHtml.tsx +29 -0
- package/templates/ssg/tsconfig.json +22 -0
- package/templates/ssg/vike.d.ts +25 -0
- package/templates/ssg/vite.config.ts +7 -0
- package/templates/ssg-netlify/app/constants.mjs +30 -0
- package/templates/ssg-vercel/app/constants.mjs +26 -0
- package/templates/ssg-vercel/public/vercel.json +11 -0
- package/templates/vercel/.vercelignore +8 -0
- package/templates/vercel/app/constants.mjs +25 -0
- package/templates/vercel/package.json +1 -0
- package/templates/vercel/vercel.json +11 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MetaFunction,
|
|
3
|
+
type LinksFunction,
|
|
4
|
+
type LinkDescriptor,
|
|
5
|
+
type ActionFunctionArgs,
|
|
6
|
+
type LoaderFunctionArgs,
|
|
7
|
+
type HeadersFunction,
|
|
8
|
+
data,
|
|
9
|
+
redirect,
|
|
10
|
+
useLoaderData,
|
|
11
|
+
} from "react-router";
|
|
12
|
+
import {
|
|
13
|
+
isLocalResource,
|
|
14
|
+
loadResource,
|
|
15
|
+
loadResources,
|
|
16
|
+
formIdFieldName,
|
|
17
|
+
formBotFieldName,
|
|
18
|
+
} from "@webstudio-is/sdk/runtime";
|
|
19
|
+
import {
|
|
20
|
+
ReactSdkContext,
|
|
21
|
+
PageSettingsMeta,
|
|
22
|
+
PageSettingsTitle,
|
|
23
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
24
|
+
import {
|
|
25
|
+
Page,
|
|
26
|
+
siteName,
|
|
27
|
+
favIconAsset,
|
|
28
|
+
pageFontAssets,
|
|
29
|
+
pageBackgroundImageAssets,
|
|
30
|
+
} from "__CLIENT__";
|
|
31
|
+
import {
|
|
32
|
+
getResources,
|
|
33
|
+
getPageMeta,
|
|
34
|
+
getRemixParams,
|
|
35
|
+
projectId,
|
|
36
|
+
contactEmail,
|
|
37
|
+
} from "__SERVER__";
|
|
38
|
+
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
|
|
39
|
+
import css from "__CSS__?url";
|
|
40
|
+
import { sitemap } from "__SITEMAP__";
|
|
41
|
+
|
|
42
|
+
const customFetch: typeof fetch = (input, init) => {
|
|
43
|
+
if (typeof input !== "string") {
|
|
44
|
+
return fetch(input, init);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isLocalResource(input, "sitemap.xml")) {
|
|
48
|
+
// @todo: dynamic import sitemap ???
|
|
49
|
+
const response = new Response(JSON.stringify(sitemap));
|
|
50
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
51
|
+
return Promise.resolve(response);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return fetch(input, init);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const loader = async (arg: LoaderFunctionArgs) => {
|
|
58
|
+
const url = new URL(arg.request.url);
|
|
59
|
+
const host =
|
|
60
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
61
|
+
arg.request.headers.get("host") ||
|
|
62
|
+
"";
|
|
63
|
+
url.host = host;
|
|
64
|
+
url.protocol = "https";
|
|
65
|
+
|
|
66
|
+
const params = getRemixParams(arg.params);
|
|
67
|
+
const system = {
|
|
68
|
+
params,
|
|
69
|
+
search: Object.fromEntries(url.searchParams),
|
|
70
|
+
origin: url.origin,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const resources = await loadResources(
|
|
74
|
+
customFetch,
|
|
75
|
+
getResources({ system }).data
|
|
76
|
+
);
|
|
77
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
78
|
+
|
|
79
|
+
if (pageMeta.redirect) {
|
|
80
|
+
const status =
|
|
81
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
82
|
+
? pageMeta.status
|
|
83
|
+
: 302;
|
|
84
|
+
throw redirect(pageMeta.redirect, status);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// typecheck
|
|
88
|
+
arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
|
|
89
|
+
|
|
90
|
+
if (arg.context.EXCLUDE_FROM_SEARCH) {
|
|
91
|
+
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return data(
|
|
95
|
+
{
|
|
96
|
+
host,
|
|
97
|
+
url: url.href,
|
|
98
|
+
system,
|
|
99
|
+
resources,
|
|
100
|
+
pageMeta,
|
|
101
|
+
},
|
|
102
|
+
// No way for current information to change, so add cache for 10 minutes
|
|
103
|
+
// In case of CRM Data, this should be set to 0
|
|
104
|
+
{
|
|
105
|
+
status: pageMeta.status,
|
|
106
|
+
headers: {
|
|
107
|
+
"Cache-Control": "public, max-age=600",
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const headers: HeadersFunction = () => {
|
|
114
|
+
return {
|
|
115
|
+
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
120
|
+
const metas: ReturnType<MetaFunction> = [];
|
|
121
|
+
if (data === undefined) {
|
|
122
|
+
return metas;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const origin = `https://${data.host}`;
|
|
126
|
+
|
|
127
|
+
if (siteName) {
|
|
128
|
+
metas.push({
|
|
129
|
+
"script:ld+json": {
|
|
130
|
+
"@context": "https://schema.org",
|
|
131
|
+
"@type": "WebSite",
|
|
132
|
+
name: siteName,
|
|
133
|
+
url: origin,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return metas;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const links: LinksFunction = () => {
|
|
142
|
+
const result: LinkDescriptor[] = [];
|
|
143
|
+
|
|
144
|
+
result.push({
|
|
145
|
+
rel: "stylesheet",
|
|
146
|
+
href: css,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (favIconAsset) {
|
|
150
|
+
result.push({
|
|
151
|
+
rel: "icon",
|
|
152
|
+
href: imageLoader({
|
|
153
|
+
src: `${assetBaseUrl}${favIconAsset.name}`,
|
|
154
|
+
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
|
|
155
|
+
width: 144,
|
|
156
|
+
height: 144,
|
|
157
|
+
fit: "pad",
|
|
158
|
+
quality: 100,
|
|
159
|
+
format: "auto",
|
|
160
|
+
}),
|
|
161
|
+
type: undefined,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const asset of pageFontAssets) {
|
|
166
|
+
result.push({
|
|
167
|
+
rel: "preload",
|
|
168
|
+
href: `${assetBaseUrl}${asset.name}`,
|
|
169
|
+
as: "font",
|
|
170
|
+
crossOrigin: "anonymous",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const backgroundImageAsset of pageBackgroundImageAssets) {
|
|
175
|
+
result.push({
|
|
176
|
+
rel: "preload",
|
|
177
|
+
href: `${assetBaseUrl}${backgroundImageAsset.name}`,
|
|
178
|
+
as: "image",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const getRequestHost = (request: Request): string =>
|
|
186
|
+
request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
|
|
187
|
+
|
|
188
|
+
export const action = async ({
|
|
189
|
+
request,
|
|
190
|
+
context,
|
|
191
|
+
}: ActionFunctionArgs): Promise<
|
|
192
|
+
{ success: true } | { success: false; errors: string[] }
|
|
193
|
+
> => {
|
|
194
|
+
try {
|
|
195
|
+
const url = new URL(request.url);
|
|
196
|
+
url.host = getRequestHost(request);
|
|
197
|
+
|
|
198
|
+
const formData = await request.formData();
|
|
199
|
+
|
|
200
|
+
const system = {
|
|
201
|
+
params: {},
|
|
202
|
+
search: {},
|
|
203
|
+
origin: url.origin,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const resourceName = formData.get(formIdFieldName);
|
|
207
|
+
let resource =
|
|
208
|
+
typeof resourceName === "string"
|
|
209
|
+
? getResources({ system }).action.get(resourceName)
|
|
210
|
+
: undefined;
|
|
211
|
+
|
|
212
|
+
const formBotValue = formData.get(formBotFieldName);
|
|
213
|
+
|
|
214
|
+
if (formBotValue == null || typeof formBotValue !== "string") {
|
|
215
|
+
throw new Error("Form bot field not found");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const submitTime = parseInt(formBotValue, 16);
|
|
219
|
+
// Assumes that the difference between the server time and the form submission time,
|
|
220
|
+
// including any client-server time drift, is within a 5-minute range.
|
|
221
|
+
// Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
|
|
222
|
+
// Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
|
|
223
|
+
if (
|
|
224
|
+
Number.isNaN(submitTime) ||
|
|
225
|
+
Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
|
|
226
|
+
) {
|
|
227
|
+
throw new Error(`Form bot value invalid ${formBotValue}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
formData.delete(formIdFieldName);
|
|
231
|
+
formData.delete(formBotFieldName);
|
|
232
|
+
|
|
233
|
+
if (resource) {
|
|
234
|
+
resource.headers.push({
|
|
235
|
+
name: "Content-Type",
|
|
236
|
+
value: "application/json",
|
|
237
|
+
});
|
|
238
|
+
resource.body = Object.fromEntries(formData);
|
|
239
|
+
} else {
|
|
240
|
+
if (contactEmail === undefined) {
|
|
241
|
+
throw new Error("Contact email not found");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
resource = context.getDefaultActionResource?.({
|
|
245
|
+
url,
|
|
246
|
+
projectId,
|
|
247
|
+
contactEmail,
|
|
248
|
+
formData,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (resource === undefined) {
|
|
253
|
+
throw Error("Resource not found");
|
|
254
|
+
}
|
|
255
|
+
const { ok, statusText } = await loadResource(fetch, resource);
|
|
256
|
+
if (ok) {
|
|
257
|
+
return { success: true };
|
|
258
|
+
}
|
|
259
|
+
return { success: false, errors: [statusText] };
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(error);
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
errors: [error instanceof Error ? error.message : "Unknown error"],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const Outlet = () => {
|
|
271
|
+
const { system, resources, url, pageMeta, host } =
|
|
272
|
+
useLoaderData<typeof loader>();
|
|
273
|
+
return (
|
|
274
|
+
<ReactSdkContext.Provider
|
|
275
|
+
value={{
|
|
276
|
+
imageLoader,
|
|
277
|
+
assetBaseUrl,
|
|
278
|
+
resources,
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
|
|
282
|
+
<Page key={url} system={system} />
|
|
283
|
+
<PageSettingsMeta
|
|
284
|
+
url={url}
|
|
285
|
+
pageMeta={pageMeta}
|
|
286
|
+
host={host}
|
|
287
|
+
siteName={siteName}
|
|
288
|
+
imageLoader={imageLoader}
|
|
289
|
+
/>
|
|
290
|
+
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
|
291
|
+
</ReactSdkContext.Provider>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export default Outlet;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { renderToString } from "react-dom/server";
|
|
2
|
+
import { type LoaderFunctionArgs, redirect } from "react-router";
|
|
3
|
+
import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";
|
|
4
|
+
import {
|
|
5
|
+
ReactSdkContext,
|
|
6
|
+
xmlNodeTagSuffix,
|
|
7
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
8
|
+
import { Page } from "__CLIENT__";
|
|
9
|
+
import { getPageMeta, getRemixParams, getResources } from "__SERVER__";
|
|
10
|
+
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
|
|
11
|
+
import { sitemap } from "__SITEMAP__";
|
|
12
|
+
|
|
13
|
+
const customFetch: typeof fetch = (input, init) => {
|
|
14
|
+
if (typeof input !== "string") {
|
|
15
|
+
return fetch(input, init);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (isLocalResource(input, "sitemap.xml")) {
|
|
19
|
+
// @todo: dynamic import sitemap ???
|
|
20
|
+
const response = new Response(JSON.stringify(sitemap));
|
|
21
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
22
|
+
return Promise.resolve(response);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return fetch(input, init);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const loader = async (arg: LoaderFunctionArgs) => {
|
|
29
|
+
const url = new URL(arg.request.url);
|
|
30
|
+
const host =
|
|
31
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
32
|
+
arg.request.headers.get("host") ||
|
|
33
|
+
"";
|
|
34
|
+
url.host = host;
|
|
35
|
+
url.protocol = "https";
|
|
36
|
+
|
|
37
|
+
const params = getRemixParams(arg.params);
|
|
38
|
+
|
|
39
|
+
const system = {
|
|
40
|
+
params,
|
|
41
|
+
search: Object.fromEntries(url.searchParams),
|
|
42
|
+
origin: url.origin,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const resources = await loadResources(
|
|
46
|
+
customFetch,
|
|
47
|
+
getResources({ system }).data
|
|
48
|
+
);
|
|
49
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
50
|
+
|
|
51
|
+
if (pageMeta.redirect) {
|
|
52
|
+
const status =
|
|
53
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
54
|
+
? pageMeta.status
|
|
55
|
+
: 302;
|
|
56
|
+
return redirect(pageMeta.redirect, status);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// typecheck
|
|
60
|
+
arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
|
|
61
|
+
|
|
62
|
+
let text = renderToString(
|
|
63
|
+
<ReactSdkContext.Provider
|
|
64
|
+
value={{
|
|
65
|
+
imageLoader,
|
|
66
|
+
assetBaseUrl,
|
|
67
|
+
resources,
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<Page system={system} />
|
|
71
|
+
</ReactSdkContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Xml is wrapped with <svg> to prevent React from hoisting elements like <title>, <meta>, and <link> out of their intended scope during rendering.
|
|
75
|
+
// More details: https://github.com/facebook/react/blob/7c8e5e7ab8bb63de911637892392c5efd8ce1d0f/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L3083
|
|
76
|
+
text = text.replace(/^<svg>/g, "").replace(/<\/svg>$/g, "");
|
|
77
|
+
|
|
78
|
+
// React has issues rendering certain elements, such as errors when a <link> element has children.
|
|
79
|
+
// To render XML, we wrap it with an <svg> tag and add a suffix to avoid React's default behavior on these elements.
|
|
80
|
+
text = text.replaceAll(xmlNodeTagSuffix, "");
|
|
81
|
+
|
|
82
|
+
return new Response(`<?xml version="1.0" encoding="UTF-8"?>\n${text}`, {
|
|
83
|
+
headers: { "Content-Type": "application/xml" },
|
|
84
|
+
});
|
|
85
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from "react-router";
|
|
2
|
+
|
|
3
|
+
export const loader = (arg: LoaderFunctionArgs) => {
|
|
4
|
+
const host =
|
|
5
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
6
|
+
arg.request.headers.get("host") ||
|
|
7
|
+
"";
|
|
8
|
+
|
|
9
|
+
return new Response(
|
|
10
|
+
`
|
|
11
|
+
User-agent: *
|
|
12
|
+
Disallow: /api/
|
|
13
|
+
|
|
14
|
+
Sitemap: https://${host}/sitemap.xml
|
|
15
|
+
|
|
16
|
+
`,
|
|
17
|
+
{
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "text/plain",
|
|
20
|
+
},
|
|
21
|
+
status: 200,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"private": true,
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "react-router build",
|
|
7
|
+
"dev": "react-router dev",
|
|
8
|
+
"start": "react-router-serve ./build/server/index.js",
|
|
9
|
+
"typecheck": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@react-router/dev": "^7.1.4",
|
|
13
|
+
"@react-router/fs-routes": "^7.1.4",
|
|
14
|
+
"@react-router/serve": "^7.1.4",
|
|
15
|
+
"@webstudio-is/image": "0.0.0-021f2d4",
|
|
16
|
+
"@webstudio-is/react-sdk": "0.0.0-021f2d4",
|
|
17
|
+
"@webstudio-is/sdk": "0.0.0-021f2d4",
|
|
18
|
+
"@webstudio-is/sdk-components-animation": "0.0.0-021f2d4",
|
|
19
|
+
"@webstudio-is/sdk-components-react-radix": "0.0.0-021f2d4",
|
|
20
|
+
"@webstudio-is/sdk-components-react-router": "0.0.0-021f2d4",
|
|
21
|
+
"@webstudio-is/sdk-components-react": "0.0.0-021f2d4",
|
|
22
|
+
"isbot": "^5.1.22",
|
|
23
|
+
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
24
|
+
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
25
|
+
"react-router": "^7.1.4",
|
|
26
|
+
"vite": "^5.4.11"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.2.70",
|
|
30
|
+
"@types/react-dom": "^18.2.25",
|
|
31
|
+
"typescript": "5.7.3"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["**/*.ts", "**/*.tsx", "**/*.mjs"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
+
"types": ["vite/client", "@webstudio-is/react-sdk/placeholder"],
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"target": "ES2022",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"allowJs": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"skipLibCheck": true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
FROM node:22-alpine AS dependencies-env
|
|
2
|
+
COPY .npmrc package.json /app/
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
RUN npm install --omit=dev
|
|
5
|
+
|
|
6
|
+
FROM dependencies-env AS build-env
|
|
7
|
+
COPY . /app/
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
RUN npm install
|
|
10
|
+
RUN npm run build
|
|
11
|
+
|
|
12
|
+
FROM node:22-alpine
|
|
13
|
+
COPY .npmrc package.json /app/
|
|
14
|
+
COPY --from=dependencies-env /app/node_modules /app/node_modules
|
|
15
|
+
COPY --from=build-env /app/build /app/build
|
|
16
|
+
COPY --from=build-env /app/public /app/public
|
|
17
|
+
WORKDIR /app
|
|
18
|
+
# there is a DOMAINS env with comma separated allowed domains for image processing
|
|
19
|
+
CMD ["npm", "run", "start"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
export const assetBaseUrl = "/assets/";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
9
|
+
*/
|
|
10
|
+
export const imageLoader = (props) => {
|
|
11
|
+
if (props.format === "raw") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
// handle absolute urls
|
|
15
|
+
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
|
|
16
|
+
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
|
|
17
|
+
return `/_image/w_${props.width},q_${props.quality}${path}`;
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { env } from "node:process";
|
|
2
|
+
import type { LoaderFunctionArgs } from "react-router";
|
|
3
|
+
import {
|
|
4
|
+
createIPX,
|
|
5
|
+
createIPXH3Handler,
|
|
6
|
+
ipxFSStorage,
|
|
7
|
+
ipxHttpStorage,
|
|
8
|
+
} from "ipx";
|
|
9
|
+
import { createApp, toWebHandler } from "h3";
|
|
10
|
+
|
|
11
|
+
const domains = env.DOMAINS?.split(/\s*,\s*/) ?? [];
|
|
12
|
+
|
|
13
|
+
const ipx = createIPX({
|
|
14
|
+
storage: ipxFSStorage({ dir: "./public" }),
|
|
15
|
+
httpStorage: ipxHttpStorage({ domains }),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const handleRequest = toWebHandler(
|
|
19
|
+
createApp().use("/_image", createIPXH3Handler(ipx))
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const loader = async (args: LoaderFunctionArgs) => {
|
|
23
|
+
return handleRequest(args.request);
|
|
24
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
export const assetBaseUrl = "/assets/";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
9
|
+
*/
|
|
10
|
+
export const imageLoader = (props) => {
|
|
11
|
+
if (process.env.NODE_ENV !== "production") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (props.format === "raw") {
|
|
16
|
+
return props.src;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// https://docs.netlify.com/image-cdn/overview/
|
|
20
|
+
const searchParams = new URLSearchParams();
|
|
21
|
+
searchParams.set("url", props.src);
|
|
22
|
+
searchParams.set("w", props.width.toString());
|
|
23
|
+
if (props.height) {
|
|
24
|
+
searchParams.set("h", props.height.toString());
|
|
25
|
+
}
|
|
26
|
+
searchParams.set("q", props.quality.toString());
|
|
27
|
+
// fit=contain by default
|
|
28
|
+
return `/.netlify/images?${searchParams}`;
|
|
29
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"**/*.ts",
|
|
4
|
+
"**/*.tsx",
|
|
5
|
+
"**/.server/**/*.ts",
|
|
6
|
+
"**/.server/**/*.tsx",
|
|
7
|
+
"**/.client/**/*.ts",
|
|
8
|
+
"**/.client/**/*.tsx"
|
|
9
|
+
],
|
|
10
|
+
"compilerOptions": {
|
|
11
|
+
"types": [
|
|
12
|
+
"@remix-run/cloudflare",
|
|
13
|
+
"vite/client",
|
|
14
|
+
"@cloudflare/workers-types/2023-07-01",
|
|
15
|
+
"@webstudio-is/react-sdk/placeholder"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const assetBaseUrl = "/assets/";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
10
|
+
*/
|
|
11
|
+
export const imageLoader = ({ src }) => {
|
|
12
|
+
return src;
|
|
13
|
+
};
|