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
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webstudio",
|
|
3
|
+
"version": "0.0.0-021f2d4",
|
|
4
|
+
"description": "Webstudio CLI",
|
|
5
|
+
"author": "Webstudio <github@webstudio.is>",
|
|
6
|
+
"homepage": "https://webstudio.is",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"webstudio-cli": "./bin.js",
|
|
10
|
+
"webstudio": "./bin.js"
|
|
11
|
+
},
|
|
12
|
+
"imports": {
|
|
13
|
+
"#cli": {
|
|
14
|
+
"webstudio": "./src/cli.ts",
|
|
15
|
+
"default": "./lib/cli.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib/*",
|
|
20
|
+
"templates/*",
|
|
21
|
+
"bin.js",
|
|
22
|
+
"!*.{test,stories}.*"
|
|
23
|
+
],
|
|
24
|
+
"license": "AGPL-3.0-or-later",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20.12"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@clack/prompts": "^0.9.1",
|
|
30
|
+
"@emotion/hash": "^0.9.2",
|
|
31
|
+
"acorn": "^8.14.0",
|
|
32
|
+
"acorn-walk": "^8.3.4",
|
|
33
|
+
"change-case": "^5.4.4",
|
|
34
|
+
"deepmerge": "^4.3.1",
|
|
35
|
+
"env-paths": "^3.0.0",
|
|
36
|
+
"nanoid": "^5.0.9",
|
|
37
|
+
"p-limit": "^6.2.0",
|
|
38
|
+
"parse5": "7.2.1",
|
|
39
|
+
"picocolors": "^1.1.1",
|
|
40
|
+
"reserved-identifiers": "^1.0.0",
|
|
41
|
+
"tinyexec": "^0.3.2",
|
|
42
|
+
"yargs": "^17.7.2",
|
|
43
|
+
"zod": "^3.22.4"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@netlify/remix-adapter": "^2.5.1",
|
|
47
|
+
"@netlify/remix-edge-adapter": "3.4.2",
|
|
48
|
+
"@netlify/vite-plugin-react-router": "^1.0.0",
|
|
49
|
+
"@react-router/dev": "^7.1.4",
|
|
50
|
+
"@react-router/fs-routes": "^7.1.4",
|
|
51
|
+
"@remix-run/cloudflare": "^2.15.2",
|
|
52
|
+
"@remix-run/cloudflare-pages": "^2.15.2",
|
|
53
|
+
"@remix-run/dev": "^2.15.2",
|
|
54
|
+
"@remix-run/node": "^2.15.2",
|
|
55
|
+
"@remix-run/react": "^2.15.2",
|
|
56
|
+
"@remix-run/server-runtime": "^2.15.2",
|
|
57
|
+
"@types/react": "^18.2.70",
|
|
58
|
+
"@types/react-dom": "^18.2.25",
|
|
59
|
+
"@types/yargs": "^17.0.33",
|
|
60
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
61
|
+
"h3": "^1.14.0",
|
|
62
|
+
"ipx": "^3.0.1",
|
|
63
|
+
"prettier": "3.4.2",
|
|
64
|
+
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
65
|
+
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
66
|
+
"react-router": "^7.1.4",
|
|
67
|
+
"ts-expect": "^1.3.0",
|
|
68
|
+
"vike": "^0.4.220",
|
|
69
|
+
"vite": "^5.4.11",
|
|
70
|
+
"vitest": "^3.0.2",
|
|
71
|
+
"wrangler": "^3.63.2",
|
|
72
|
+
"@webstudio-is/http-client": "0.0.0-021f2d4",
|
|
73
|
+
"@webstudio-is/image": "0.0.0-021f2d4",
|
|
74
|
+
"@webstudio-is/react-sdk": "0.0.0-021f2d4",
|
|
75
|
+
"@webstudio-is/sdk": "0.0.0-021f2d4",
|
|
76
|
+
"@webstudio-is/sdk-components-animation": "0.0.0-021f2d4",
|
|
77
|
+
"@webstudio-is/sdk-components-react": "0.0.0-021f2d4",
|
|
78
|
+
"@webstudio-is/sdk-components-react-radix": "0.0.0-021f2d4",
|
|
79
|
+
"@webstudio-is/sdk-components-react-remix": "0.0.0-021f2d4",
|
|
80
|
+
"@webstudio-is/sdk-components-react-router": "0.0.0-021f2d4",
|
|
81
|
+
"@webstudio-is/tsconfig": "1.0.7"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"typecheck": "tsc",
|
|
85
|
+
"build": "rm -rf lib && vite build",
|
|
86
|
+
"test": "vitest run"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Welcome to Remix + Vite!
|
|
2
|
+
|
|
3
|
+
📖 See the [Remix docs](https://remix.run/docs) and the [Remix Vite docs](https://remix.run/docs/en/main/future/vite) for details on supported features.
|
|
4
|
+
|
|
5
|
+
## Typegen
|
|
6
|
+
|
|
7
|
+
Generate types for your Cloudflare bindings in `wrangler.toml`:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm run typegen
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You will need to rerun typegen whenever you make changes to `wrangler.toml`.
|
|
14
|
+
|
|
15
|
+
## Development
|
|
16
|
+
|
|
17
|
+
Run the Vite dev server:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm run dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To run Wrangler:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm run build
|
|
27
|
+
npm run start
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Deployment
|
|
31
|
+
|
|
32
|
+
> [!WARNING]
|
|
33
|
+
> Cloudflare does _not_ use `wrangler.toml` to configure deployment bindings.
|
|
34
|
+
> You **MUST** [configure deployment bindings manually in the Cloudflare dashboard][bindings].
|
|
35
|
+
|
|
36
|
+
First, build your app for production:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npm run build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then, deploy your app to Cloudflare Pages:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm run deploy
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
[bindings]: https://developers.cloudflare.com/pages/functions/bindings/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
// @ts-ignore - the server build file is generated by `remix vite:build`
|
|
5
|
+
import * as build from "../build/server";
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore - the server build file is generated by `remix vite:build`
|
|
9
|
+
export const onRequest = createPagesFunctionHandler({ build });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"sideEffects": false,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "remix vite:build",
|
|
7
|
+
"deploy": "npm run build && wrangler pages deploy ./build/client",
|
|
8
|
+
"dev": "remix vite:dev",
|
|
9
|
+
"start": "wrangler pages dev ./build/client",
|
|
10
|
+
"typegen": "wrangler types",
|
|
11
|
+
"preview": "npm run build && wrangler pages dev ./build/client",
|
|
12
|
+
"build-cf-types": "wrangler types"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@remix-run/cloudflare": "2.15.2",
|
|
16
|
+
"@remix-run/cloudflare-pages": "2.15.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@cloudflare/workers-types": "^4.20240620.0",
|
|
20
|
+
"wrangler": "^3.63.2"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -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,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
vitePlugin as remix,
|
|
3
|
+
cloudflareDevProxyVitePlugin as remixCloudflareDevProxy,
|
|
4
|
+
} from "@remix-run/dev";
|
|
5
|
+
import { defineConfig } from "vite";
|
|
6
|
+
|
|
7
|
+
export default defineConfig(({ mode }) => ({
|
|
8
|
+
plugins: [
|
|
9
|
+
// without this, remixCloudflareDevProxy trying to load workerd even for production (it's not needed for production)
|
|
10
|
+
mode === "production" ? undefined : remixCloudflareDevProxy(),
|
|
11
|
+
remix({
|
|
12
|
+
future: {
|
|
13
|
+
v3_lazyRouteDiscovery: false,
|
|
14
|
+
v3_relativeSplatPath: false,
|
|
15
|
+
v3_singleFetch: false,
|
|
16
|
+
v3_fetcherPersist: false,
|
|
17
|
+
v3_throwAbortReason: false,
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
].filter(Boolean),
|
|
21
|
+
}));
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#:schema node_modules/wrangler/config-schema.json
|
|
2
|
+
# https://developers.cloudflare.com/pages/functions/wrangler-configuration/
|
|
3
|
+
name = "webstudio-remix-app"
|
|
4
|
+
compatibility_date = "2024-04-05"
|
|
5
|
+
pages_build_output_dir="./build"
|
|
6
|
+
|
|
7
|
+
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
8
|
+
# Note: Use secrets to store sensitive data.
|
|
9
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
|
|
10
|
+
# [vars]
|
|
11
|
+
# MY_VARIABLE = "production_value"
|
|
12
|
+
|
|
13
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
14
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
|
|
15
|
+
# [ai]
|
|
16
|
+
# binding = "AI"
|
|
17
|
+
|
|
18
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
19
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
|
|
20
|
+
# [[d1_databases]]
|
|
21
|
+
# binding = "MY_DB"
|
|
22
|
+
# database_name = "my-database"
|
|
23
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
24
|
+
|
|
25
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
26
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
27
|
+
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
|
|
28
|
+
# [[durable_objects.bindings]]
|
|
29
|
+
# name = "MY_DURABLE_OBJECT"
|
|
30
|
+
# class_name = "MyDurableObject"
|
|
31
|
+
# script_name = 'my-durable-object'
|
|
32
|
+
|
|
33
|
+
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
34
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
|
|
35
|
+
# [[kv_namespaces]]
|
|
36
|
+
# binding = "MY_KV_NAMESPACE"
|
|
37
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
38
|
+
|
|
39
|
+
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
40
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
|
|
41
|
+
# [[queues.producers]]
|
|
42
|
+
# binding = "MY_QUEUE"
|
|
43
|
+
# queue = "my-queue"
|
|
44
|
+
|
|
45
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
46
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
|
|
47
|
+
# [[r2_buckets]]
|
|
48
|
+
# binding = "MY_BUCKET"
|
|
49
|
+
# bucket_name = "my-bucket"
|
|
50
|
+
|
|
51
|
+
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
52
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
|
|
53
|
+
# [[services]]
|
|
54
|
+
# binding = "MY_SERVICE"
|
|
55
|
+
# service = "my-service"
|
|
@@ -0,0 +1,12 @@
|
|
|
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 = ({ src }) => {
|
|
11
|
+
return src;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { AppLoadContext } from "@remix-run/server-runtime";
|
|
4
|
+
import { ResourceRequest } from "@webstudio-is/sdk";
|
|
5
|
+
|
|
6
|
+
declare module "@remix-run/server-runtime" {
|
|
7
|
+
interface AppLoadContext {
|
|
8
|
+
EXCLUDE_FROM_SEARCH: boolean;
|
|
9
|
+
getDefaultActionResource?: (options: {
|
|
10
|
+
url: URL;
|
|
11
|
+
projectId: string;
|
|
12
|
+
contactEmail: string;
|
|
13
|
+
formData: FormData;
|
|
14
|
+
}) => ResourceRequest;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
|
|
3
|
+
import { Links, Meta, Outlet, useMatches } from "@remix-run/react";
|
|
4
|
+
// @todo think about how to make __generated__ typeable
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { CustomCode } from "./__generated__/_index";
|
|
7
|
+
|
|
8
|
+
const Root = () => {
|
|
9
|
+
// Get language from matches
|
|
10
|
+
const matches = useMatches();
|
|
11
|
+
|
|
12
|
+
const lastMatchWithLanguage = matches.findLast((match) => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const language = match?.data?.pageMeta?.language;
|
|
15
|
+
return language != null;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const lang = lastMatchWithLanguage?.data?.pageMeta?.language ?? "en";
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<html lang={lang}>
|
|
23
|
+
<head>
|
|
24
|
+
<meta charSet="utf-8" />
|
|
25
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
26
|
+
<Meta />
|
|
27
|
+
<Links />
|
|
28
|
+
<CustomCode />
|
|
29
|
+
</head>
|
|
30
|
+
<Outlet />
|
|
31
|
+
</html>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default Root;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
|
|
2
|
+
import { sitemap } from "__SITEMAP__";
|
|
3
|
+
|
|
4
|
+
export const loader = (arg: LoaderFunctionArgs) => {
|
|
5
|
+
const host =
|
|
6
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
7
|
+
arg.request.headers.get("host") ||
|
|
8
|
+
"";
|
|
9
|
+
|
|
10
|
+
const urls = sitemap.map((page) => {
|
|
11
|
+
const url = new URL(`https://${host}${page.path}`);
|
|
12
|
+
|
|
13
|
+
return `
|
|
14
|
+
<url>
|
|
15
|
+
<loc>${url.href}</loc>
|
|
16
|
+
<lastmod>${page.lastModified.split("T")[0]}</lastmod>
|
|
17
|
+
</url>
|
|
18
|
+
`;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return new Response(
|
|
22
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
23
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
24
|
+
${urls.join("")}
|
|
25
|
+
</urlset>
|
|
26
|
+
`,
|
|
27
|
+
{
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/xml",
|
|
30
|
+
},
|
|
31
|
+
status: 200,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ServerRuntimeMetaFunction as MetaFunction,
|
|
3
|
+
type LinksFunction,
|
|
4
|
+
type LinkDescriptor,
|
|
5
|
+
type ActionFunctionArgs,
|
|
6
|
+
type LoaderFunctionArgs,
|
|
7
|
+
type HeadersFunction,
|
|
8
|
+
json,
|
|
9
|
+
redirect,
|
|
10
|
+
} from "@remix-run/server-runtime";
|
|
11
|
+
import { useLoaderData } from "@remix-run/react";
|
|
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
|
+
PageSettingsCanonicalLink,
|
|
24
|
+
} from "@webstudio-is/react-sdk/runtime";
|
|
25
|
+
import {
|
|
26
|
+
Page,
|
|
27
|
+
siteName,
|
|
28
|
+
favIconAsset,
|
|
29
|
+
pageFontAssets,
|
|
30
|
+
pageBackgroundImageAssets,
|
|
31
|
+
} from "__CLIENT__";
|
|
32
|
+
import {
|
|
33
|
+
getResources,
|
|
34
|
+
getPageMeta,
|
|
35
|
+
getRemixParams,
|
|
36
|
+
projectId,
|
|
37
|
+
contactEmail,
|
|
38
|
+
} from "__SERVER__";
|
|
39
|
+
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
|
|
40
|
+
import css from "__CSS__?url";
|
|
41
|
+
import { sitemap } from "__SITEMAP__";
|
|
42
|
+
|
|
43
|
+
const customFetch: typeof fetch = (input, init) => {
|
|
44
|
+
if (typeof input !== "string") {
|
|
45
|
+
return fetch(input, init);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isLocalResource(input, "sitemap.xml")) {
|
|
49
|
+
// @todo: dynamic import sitemap ???
|
|
50
|
+
const response = new Response(JSON.stringify(sitemap));
|
|
51
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
52
|
+
return Promise.resolve(response);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return fetch(input, init);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const loader = async (arg: LoaderFunctionArgs) => {
|
|
59
|
+
const url = new URL(arg.request.url);
|
|
60
|
+
const host =
|
|
61
|
+
arg.request.headers.get("x-forwarded-host") ||
|
|
62
|
+
arg.request.headers.get("host") ||
|
|
63
|
+
"";
|
|
64
|
+
url.host = host;
|
|
65
|
+
url.protocol = "https";
|
|
66
|
+
|
|
67
|
+
const params = getRemixParams(arg.params);
|
|
68
|
+
const system = {
|
|
69
|
+
params,
|
|
70
|
+
search: Object.fromEntries(url.searchParams),
|
|
71
|
+
origin: url.origin,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const resources = await loadResources(
|
|
75
|
+
customFetch,
|
|
76
|
+
getResources({ system }).data
|
|
77
|
+
);
|
|
78
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
79
|
+
|
|
80
|
+
if (pageMeta.redirect) {
|
|
81
|
+
const status =
|
|
82
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
83
|
+
? pageMeta.status
|
|
84
|
+
: 302;
|
|
85
|
+
return redirect(pageMeta.redirect, status);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// typecheck
|
|
89
|
+
arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
|
|
90
|
+
|
|
91
|
+
if (arg.context.EXCLUDE_FROM_SEARCH) {
|
|
92
|
+
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return json(
|
|
96
|
+
{
|
|
97
|
+
host,
|
|
98
|
+
url: url.href,
|
|
99
|
+
system,
|
|
100
|
+
resources,
|
|
101
|
+
pageMeta,
|
|
102
|
+
},
|
|
103
|
+
// No way for current information to change, so add cache for 10 minutes
|
|
104
|
+
// In case of CRM Data, this should be set to 0
|
|
105
|
+
{
|
|
106
|
+
status: pageMeta.status,
|
|
107
|
+
headers: {
|
|
108
|
+
"Cache-Control": "public, max-age=600",
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const headers: HeadersFunction = () => {
|
|
115
|
+
return {
|
|
116
|
+
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
121
|
+
const metas: ReturnType<MetaFunction> = [];
|
|
122
|
+
if (data === undefined) {
|
|
123
|
+
return metas;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const origin = `https://${data.host}`;
|
|
127
|
+
|
|
128
|
+
if (siteName) {
|
|
129
|
+
metas.push({
|
|
130
|
+
"script:ld+json": {
|
|
131
|
+
"@context": "https://schema.org",
|
|
132
|
+
"@type": "WebSite",
|
|
133
|
+
name: siteName,
|
|
134
|
+
url: origin,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return metas;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const links: LinksFunction = () => {
|
|
143
|
+
const result: LinkDescriptor[] = [];
|
|
144
|
+
|
|
145
|
+
result.push({
|
|
146
|
+
rel: "stylesheet",
|
|
147
|
+
href: css,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (favIconAsset) {
|
|
151
|
+
result.push({
|
|
152
|
+
rel: "icon",
|
|
153
|
+
href: imageLoader({
|
|
154
|
+
src: `${assetBaseUrl}${favIconAsset.name}`,
|
|
155
|
+
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
|
|
156
|
+
width: 144,
|
|
157
|
+
height: 144,
|
|
158
|
+
fit: "pad",
|
|
159
|
+
quality: 100,
|
|
160
|
+
format: "auto",
|
|
161
|
+
}),
|
|
162
|
+
type: undefined,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (const asset of pageFontAssets) {
|
|
167
|
+
result.push({
|
|
168
|
+
rel: "preload",
|
|
169
|
+
href: `${assetBaseUrl}${asset.name}`,
|
|
170
|
+
as: "font",
|
|
171
|
+
crossOrigin: "anonymous",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const backgroundImageAsset of pageBackgroundImageAssets) {
|
|
176
|
+
result.push({
|
|
177
|
+
rel: "preload",
|
|
178
|
+
href: `${assetBaseUrl}${backgroundImageAsset.name}`,
|
|
179
|
+
as: "image",
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const getRequestHost = (request: Request): string =>
|
|
187
|
+
request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
|
|
188
|
+
|
|
189
|
+
export const action = async ({
|
|
190
|
+
request,
|
|
191
|
+
context,
|
|
192
|
+
}: ActionFunctionArgs): Promise<
|
|
193
|
+
{ success: true } | { success: false; errors: string[] }
|
|
194
|
+
> => {
|
|
195
|
+
try {
|
|
196
|
+
const url = new URL(request.url);
|
|
197
|
+
url.host = getRequestHost(request);
|
|
198
|
+
|
|
199
|
+
const formData = await request.formData();
|
|
200
|
+
|
|
201
|
+
const system = {
|
|
202
|
+
params: {},
|
|
203
|
+
search: {},
|
|
204
|
+
origin: url.origin,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const resourceName = formData.get(formIdFieldName);
|
|
208
|
+
let resource =
|
|
209
|
+
typeof resourceName === "string"
|
|
210
|
+
? getResources({ system }).action.get(resourceName)
|
|
211
|
+
: undefined;
|
|
212
|
+
|
|
213
|
+
const formBotValue = formData.get(formBotFieldName);
|
|
214
|
+
|
|
215
|
+
if (formBotValue == null || typeof formBotValue !== "string") {
|
|
216
|
+
throw new Error("Form bot field not found");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const submitTime = parseInt(formBotValue, 16);
|
|
220
|
+
// Assumes that the difference between the server time and the form submission time,
|
|
221
|
+
// including any client-server time drift, is within a 5-minute range.
|
|
222
|
+
// Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
|
|
223
|
+
// Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
|
|
224
|
+
if (
|
|
225
|
+
Number.isNaN(submitTime) ||
|
|
226
|
+
Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
|
|
227
|
+
) {
|
|
228
|
+
throw new Error(`Form bot value invalid ${formBotValue}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
formData.delete(formIdFieldName);
|
|
232
|
+
formData.delete(formBotFieldName);
|
|
233
|
+
|
|
234
|
+
if (resource) {
|
|
235
|
+
resource.headers.push({
|
|
236
|
+
name: "Content-Type",
|
|
237
|
+
value: "application/json",
|
|
238
|
+
});
|
|
239
|
+
resource.body = Object.fromEntries(formData);
|
|
240
|
+
} else {
|
|
241
|
+
if (contactEmail === undefined) {
|
|
242
|
+
throw new Error("Contact email not found");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
resource = context.getDefaultActionResource?.({
|
|
246
|
+
url,
|
|
247
|
+
projectId,
|
|
248
|
+
contactEmail,
|
|
249
|
+
formData,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (resource === undefined) {
|
|
254
|
+
throw Error("Resource not found");
|
|
255
|
+
}
|
|
256
|
+
const { ok, statusText } = await loadResource(fetch, resource);
|
|
257
|
+
if (ok) {
|
|
258
|
+
return { success: true };
|
|
259
|
+
}
|
|
260
|
+
return { success: false, errors: [statusText] };
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error(error);
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
success: false,
|
|
266
|
+
errors: [error instanceof Error ? error.message : "Unknown error"],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const Outlet = () => {
|
|
272
|
+
const { system, resources, url, pageMeta, host } =
|
|
273
|
+
useLoaderData<typeof loader>();
|
|
274
|
+
return (
|
|
275
|
+
<ReactSdkContext.Provider
|
|
276
|
+
value={{
|
|
277
|
+
imageLoader,
|
|
278
|
+
assetBaseUrl,
|
|
279
|
+
resources,
|
|
280
|
+
}}
|
|
281
|
+
>
|
|
282
|
+
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
|
|
283
|
+
<Page key={url} system={system} />
|
|
284
|
+
<PageSettingsMeta
|
|
285
|
+
url={url}
|
|
286
|
+
pageMeta={pageMeta}
|
|
287
|
+
host={host}
|
|
288
|
+
siteName={siteName}
|
|
289
|
+
imageLoader={imageLoader}
|
|
290
|
+
/>
|
|
291
|
+
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
|
292
|
+
<PageSettingsCanonicalLink href={url} />
|
|
293
|
+
</ReactSdkContext.Provider>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export default Outlet;
|