@lowdefy/server-e2e 5.6.0 → 6.1.0

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.
Files changed (45) hide show
  1. package/{pages/_app.js → client/App.jsx} +43 -28
  2. package/client/Page.jsx +110 -0
  3. package/client/main.jsx +39 -0
  4. package/lib/build/app.js +8 -1
  5. package/lib/build/appMeta.js +8 -1
  6. package/lib/build/auth.js +8 -1
  7. package/lib/build/config.js +8 -1
  8. package/lib/build/i18n.js +26 -0
  9. package/lib/build/logger.js +8 -1
  10. package/lib/build/theme.js +8 -1
  11. package/lib/client/auth/{Auth.js → Auth.jsx} +5 -1
  12. package/lib/server/auth/{getServerSession.js → session.js} +5 -3
  13. package/lib/server/log/createHandleError.test.mjs +126 -0
  14. package/lib/server/scrubSecrets.js +25 -0
  15. package/lowdefy/createCustomPluginTypesMap.mjs +1 -0
  16. package/lowdefy/createCustomPluginTypesMap.test.mjs +2 -0
  17. package/package.json +49 -43
  18. package/package.original.json +52 -46
  19. package/postcss.config.cjs +1 -0
  20. package/src/app.js +78 -0
  21. package/src/html/getAssets.js +45 -0
  22. package/src/html/renderPage.js +79 -0
  23. package/src/html/template.js +95 -0
  24. package/src/index.js +40 -0
  25. package/src/lib/getPathSegments.js +25 -0
  26. package/src/lib/safeScriptJson.js +38 -0
  27. package/src/middleware/apiContext.js +84 -0
  28. package/src/middleware/apiContext.test.mjs +109 -0
  29. package/src/middleware/errorHandler.js +39 -0
  30. package/src/routes/apiPage.js +37 -0
  31. package/{pages/api/client-error.js → src/routes/clientError.js} +14 -18
  32. package/{pages/api/endpoints/[...endpointId].js → src/routes/endpoints.js} +8 -7
  33. package/{pages/api/request/[...path].js → src/routes/request.js} +10 -10
  34. package/{pages/api/auth/session.js → src/routes/sessionMock.js} +4 -5
  35. package/{pages/api → src/routes}/usage.js +11 -8
  36. package/src/routes/websocket.js +46 -0
  37. package/vite.config.js +45 -0
  38. package/.eslintrc.yaml +0 -1
  39. package/lib/client/Page.js +0 -57
  40. package/lib/server/apiWrapper.js +0 -73
  41. package/lib/server/serverSidePropsWrapper.js +0 -64
  42. package/next.config.js +0 -20
  43. package/pages/404.js +0 -49
  44. package/pages/[[...pageId]].js +0 -85
  45. package/pages/_document.js +0 -108
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-e2e",
3
- "version": "5.6.0",
3
+ "version": "6.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy e2e testing server with cookie-based user injection",
6
6
  "homepage": "https://lowdefy.com",
@@ -30,71 +30,77 @@
30
30
  "files": [
31
31
  "lib/*",
32
32
  "lowdefy/*",
33
- "pages/*",
34
33
  "public_default/*",
35
- "next.config.js",
36
34
  "package.original.json",
37
35
  ".eslintrc.yaml",
38
- ".npmrc"
36
+ ".npmrc",
37
+ "src/*",
38
+ "client/*",
39
+ "vite.config.js",
40
+ "postcss.config.cjs"
39
41
  ],
40
42
  "dependencies": {
41
43
  "@ant-design/cssinjs": "2.1.2",
42
- "@lowdefy/actions-core": "5.6.0",
43
- "@lowdefy/api": "5.6.0",
44
- "@lowdefy/block-utils": "5.6.0",
45
- "@lowdefy/blocks-antd": "5.6.0",
46
- "@lowdefy/blocks-antd-x": "5.6.0",
47
- "@lowdefy/blocks-basic": "5.6.0",
48
- "@lowdefy/blocks-loaders": "5.6.0",
49
- "@lowdefy/blocks-markdown": "5.6.0",
50
- "@lowdefy/blocks-tiptap": "5.6.0",
51
- "@lowdefy/client": "5.6.0",
52
- "@lowdefy/connection-axios-http": "5.6.0",
53
- "@lowdefy/connection-mongodb": "5.6.0",
54
- "@lowdefy/errors": "5.6.0",
55
- "@lowdefy/helpers": "5.6.0",
56
- "@lowdefy/layout": "5.6.0",
57
- "@lowdefy/logger": "5.6.0",
58
- "@lowdefy/node-utils": "5.6.0",
59
- "@lowdefy/operators-js": "5.6.0",
60
- "@lowdefy/operators-nunjucks": "5.6.0",
61
- "@lowdefy/operators-uuid": "5.6.0",
62
- "@tailwindcss/postcss": "4.2.1",
44
+ "@ant-design/x": "2.7.0",
45
+ "@hono/node-server": "2.0.10",
46
+ "@lowdefy/actions-core": "6.1.0",
47
+ "@lowdefy/api": "6.1.0",
48
+ "@lowdefy/block-utils": "6.1.0",
49
+ "@lowdefy/blocks-aggrid": "6.1.0",
50
+ "@lowdefy/blocks-antd": "6.1.0",
51
+ "@lowdefy/blocks-antd-x": "6.1.0",
52
+ "@lowdefy/blocks-basic": "6.1.0",
53
+ "@lowdefy/blocks-echarts": "6.1.0",
54
+ "@lowdefy/blocks-loaders": "6.1.0",
55
+ "@lowdefy/blocks-markdown": "6.1.0",
56
+ "@lowdefy/blocks-tiptap": "6.1.0",
57
+ "@lowdefy/client": "6.1.0",
58
+ "@lowdefy/connection-axios-http": "6.1.0",
59
+ "@lowdefy/connection-mongodb": "6.1.0",
60
+ "@lowdefy/errors": "6.1.0",
61
+ "@lowdefy/helpers": "6.1.0",
62
+ "@lowdefy/layout": "6.1.0",
63
+ "@lowdefy/logger": "6.1.0",
64
+ "@lowdefy/node-utils": "6.1.0",
65
+ "@lowdefy/operators-js": "6.1.0",
66
+ "@lowdefy/operators-nunjucks": "6.1.0",
67
+ "@lowdefy/operators-uuid": "6.1.0",
68
+ "@lowdefy/websockets-core": "6.1.0",
69
+ "@tailwindcss/postcss": "4.3.1",
70
+ "@vitejs/plugin-react": "6.0.2",
63
71
  "antd": "6.3.1",
64
- "dayjs": "1.11.19",
65
- "next": "16.1.6",
66
- "pino": "8.16.2",
72
+ "dayjs": "1.11.20",
73
+ "hono": "4.13.5",
74
+ "pino": "10.3.1",
67
75
  "react": "18.2.0",
68
76
  "react-dom": "18.2.0",
69
77
  "react-icons": "5.6.0",
70
- "tailwindcss": "4.2.1",
71
- "uuid": "13.0.0"
78
+ "tailwindcss": "4.3.1",
79
+ "uuid": "14.0.0",
80
+ "vite": "8.0.16",
81
+ "ws": "8.21.0"
72
82
  },
73
83
  "devDependencies": {
74
84
  "@jest/globals": "28.1.3",
75
- "@lowdefy/build": "5.6.0",
76
- "@next/eslint-plugin-next": "16.1.6",
77
- "@tailwindcss/postcss": "4.2.1",
85
+ "@lowdefy/build": "6.1.0",
86
+ "@tailwindcss/postcss": "4.3.1",
78
87
  "jest": "28.1.3",
79
- "tailwindcss": "4.2.1",
80
- "webpack": "5.94.0",
81
- "yaml": "2.3.4",
82
- "yargs": "17.7.2"
88
+ "tailwindcss": "4.3.1",
89
+ "yaml": "2.9.0",
90
+ "yargs": "18.0.0"
83
91
  },
84
92
  "engines": {
85
- "node": ">=18"
93
+ "node": ">=22"
86
94
  },
87
95
  "publishConfig": {
88
96
  "access": "public"
89
97
  },
98
+ "type": "module",
90
99
  "scripts": {
91
100
  "build": "cp package.json package.original.json || copy package.json package.original.json",
101
+ "build:client": "vite build",
92
102
  "build:lowdefy": "node lowdefy/build.mjs",
93
- "build:next": "next build",
94
- "dev": "next dev",
95
- "start": "next start",
96
- "lint": "next lint",
97
- "next": "next",
103
+ "start": "node src/index.js",
98
104
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
99
105
  }
100
106
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-e2e",
3
- "version": "5.6.0",
3
+ "version": "6.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy e2e testing server with cookie-based user injection",
6
6
  "homepage": "https://lowdefy.com",
@@ -30,72 +30,78 @@
30
30
  "files": [
31
31
  "lib/*",
32
32
  "lowdefy/*",
33
- "pages/*",
34
33
  "public_default/*",
35
- "next.config.js",
36
34
  "package.original.json",
37
35
  ".eslintrc.yaml",
38
- ".npmrc"
36
+ ".npmrc",
37
+ "src/*",
38
+ "client/*",
39
+ "vite.config.js",
40
+ "postcss.config.cjs"
39
41
  ],
40
42
  "scripts": {
41
43
  "build": "cp package.json package.original.json || copy package.json package.original.json",
44
+ "build:client": "vite build",
42
45
  "build:lowdefy": "node lowdefy/build.mjs",
43
- "build:next": "next build",
44
- "dev": "next dev",
45
- "start": "next start",
46
- "lint": "next lint",
47
- "next": "next",
48
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
49
- "prepublishOnly": "pnpm build"
46
+ "prepublishOnly": "pnpm build",
47
+ "start": "node src/index.js",
48
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
50
49
  },
51
50
  "dependencies": {
52
51
  "@ant-design/cssinjs": "2.1.2",
53
- "@lowdefy/actions-core": "5.6.0",
54
- "@lowdefy/api": "5.6.0",
55
- "@lowdefy/block-utils": "5.6.0",
56
- "@lowdefy/blocks-antd": "5.6.0",
57
- "@lowdefy/blocks-antd-x": "5.6.0",
58
- "@lowdefy/blocks-basic": "5.6.0",
59
- "@lowdefy/blocks-loaders": "5.6.0",
60
- "@lowdefy/blocks-markdown": "5.6.0",
61
- "@lowdefy/blocks-tiptap": "5.6.0",
62
- "@lowdefy/client": "5.6.0",
63
- "@lowdefy/connection-axios-http": "5.6.0",
64
- "@lowdefy/connection-mongodb": "5.6.0",
65
- "@lowdefy/errors": "5.6.0",
66
- "@lowdefy/helpers": "5.6.0",
67
- "@lowdefy/layout": "5.6.0",
68
- "@lowdefy/logger": "5.6.0",
69
- "@lowdefy/node-utils": "5.6.0",
70
- "@lowdefy/operators-js": "5.6.0",
71
- "@lowdefy/operators-nunjucks": "5.6.0",
72
- "@lowdefy/operators-uuid": "5.6.0",
73
- "@tailwindcss/postcss": "4.2.1",
52
+ "@ant-design/x": "2.7.0",
53
+ "@hono/node-server": "2.0.10",
54
+ "@lowdefy/actions-core": "6.1.0",
55
+ "@lowdefy/api": "6.1.0",
56
+ "@lowdefy/block-utils": "6.1.0",
57
+ "@lowdefy/blocks-aggrid": "6.1.0",
58
+ "@lowdefy/blocks-antd": "6.1.0",
59
+ "@lowdefy/blocks-antd-x": "6.1.0",
60
+ "@lowdefy/blocks-basic": "6.1.0",
61
+ "@lowdefy/blocks-echarts": "6.1.0",
62
+ "@lowdefy/blocks-loaders": "6.1.0",
63
+ "@lowdefy/blocks-markdown": "6.1.0",
64
+ "@lowdefy/blocks-tiptap": "6.1.0",
65
+ "@lowdefy/client": "6.1.0",
66
+ "@lowdefy/connection-axios-http": "6.1.0",
67
+ "@lowdefy/connection-mongodb": "6.1.0",
68
+ "@lowdefy/errors": "6.1.0",
69
+ "@lowdefy/helpers": "6.1.0",
70
+ "@lowdefy/layout": "6.1.0",
71
+ "@lowdefy/logger": "6.1.0",
72
+ "@lowdefy/node-utils": "6.1.0",
73
+ "@lowdefy/operators-js": "6.1.0",
74
+ "@lowdefy/operators-nunjucks": "6.1.0",
75
+ "@lowdefy/operators-uuid": "6.1.0",
76
+ "@lowdefy/websockets-core": "6.1.0",
77
+ "@tailwindcss/postcss": "4.3.1",
78
+ "@vitejs/plugin-react": "6.0.2",
74
79
  "antd": "6.3.1",
75
- "dayjs": "1.11.19",
76
- "next": "16.1.6",
77
- "pino": "8.16.2",
80
+ "dayjs": "1.11.20",
81
+ "hono": "4.13.5",
82
+ "pino": "10.3.1",
78
83
  "react": "18.2.0",
79
84
  "react-dom": "18.2.0",
80
85
  "react-icons": "5.6.0",
81
- "tailwindcss": "4.2.1",
82
- "uuid": "13.0.0"
86
+ "tailwindcss": "4.3.1",
87
+ "uuid": "14.0.0",
88
+ "vite": "8.0.16",
89
+ "ws": "8.21.0"
83
90
  },
84
91
  "devDependencies": {
85
92
  "@jest/globals": "28.1.3",
86
- "@lowdefy/build": "5.6.0",
87
- "@next/eslint-plugin-next": "16.1.6",
88
- "@tailwindcss/postcss": "4.2.1",
93
+ "@lowdefy/build": "6.1.0",
94
+ "@tailwindcss/postcss": "4.3.1",
89
95
  "jest": "28.1.3",
90
- "tailwindcss": "4.2.1",
91
- "webpack": "5.94.0",
92
- "yaml": "2.3.4",
93
- "yargs": "17.7.2"
96
+ "tailwindcss": "4.3.1",
97
+ "yaml": "2.9.0",
98
+ "yargs": "18.0.0"
94
99
  },
95
100
  "engines": {
96
- "node": ">=18"
101
+ "node": ">=22"
97
102
  },
98
103
  "publishConfig": {
99
104
  "access": "public"
100
- }
105
+ },
106
+ "type": "module"
101
107
  }
@@ -0,0 +1 @@
1
+ module.exports = { plugins: { '@tailwindcss/postcss': {} } };
package/src/app.js ADDED
@@ -0,0 +1,78 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { Hono } from 'hono';
18
+ import { compress } from 'hono/compress';
19
+ import { serveStatic } from '@hono/node-server/serve-static';
20
+
21
+ import apiContext from './middleware/apiContext.js';
22
+ import apiPageHandler from './routes/apiPage.js';
23
+ import clientErrorHandler from './routes/clientError.js';
24
+ import createErrorHandler from './middleware/errorHandler.js';
25
+ import createLogger from '../lib/server/log/createLogger.js';
26
+ import endpointsHandler from './routes/endpoints.js';
27
+ import lowdefyConfig from '../lib/build/config.js';
28
+ import renderPage from './html/renderPage.js';
29
+ import requestHandler from './routes/request.js';
30
+ import sessionMockHandler from './routes/sessionMock.js';
31
+ import usageHandler from './routes/usage.js';
32
+ import websocketHandler from './routes/websocket.js';
33
+
34
+ const basePath = lowdefyConfig.basePath ?? '';
35
+
36
+ function createApp() {
37
+ const app = basePath ? new Hono().basePath(basePath) : new Hono();
38
+ const logger = createLogger({ server: 'lowdefy' });
39
+
40
+ app.use('*', async (c, next) => {
41
+ if (c.req.path.includes('/api/websocket')) {
42
+ return next();
43
+ }
44
+ return compress()(c, next);
45
+ });
46
+
47
+ app.use('/api/*', apiContext());
48
+ // Mock session endpoint — reads the lowdefy_e2e_user cookie; also the
49
+ // e2e harness health check (e2e-utils polls /api/auth/session).
50
+ app.get('/api/auth/session', sessionMockHandler);
51
+ app.all('/api/request/*', requestHandler);
52
+ app.all('/api/endpoints/*', endpointsHandler);
53
+ app.all('/api/client-error', clientErrorHandler);
54
+ app.all('/api/usage', usageHandler);
55
+ app.get('/api/websocket', websocketHandler);
56
+ app.get('/api/page/*', apiPageHandler);
57
+
58
+ // Vite build output (includes public/ via Vite's publicDir copy). Falls
59
+ // through to the page routes when no file matches.
60
+ app.use(
61
+ '/*',
62
+ serveStatic({
63
+ root: './dist/client',
64
+ rewriteRequestPath: basePath ? (path) => path.replace(basePath, '') : undefined,
65
+ })
66
+ );
67
+
68
+ app.use('/*', apiContext());
69
+ app.get('/', (c) => renderPage(c, { pageId: '' }));
70
+ app.get('/404', (c) => renderPage(c, { pageId: '404', status: 404 }));
71
+ app.get('/:rest{.+}', (c) => renderPage(c, { pageId: c.req.param('rest') }));
72
+
73
+ app.onError(createErrorHandler({ basePath, logger }));
74
+
75
+ return app;
76
+ }
77
+
78
+ export default createApp;
@@ -0,0 +1,45 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import fs from 'node:fs';
18
+ import path from 'node:path';
19
+
20
+ // The Vite manifest is read once at startup — deploys start a new server
21
+ // process after `vite build` completes, so assets never change at runtime.
22
+ // In-place deploys must build before restarting (documented).
23
+ let assets = null;
24
+
25
+ function getAssets() {
26
+ if (assets) {
27
+ return assets;
28
+ }
29
+ const manifestPath = path.join(process.cwd(), 'dist/client/.vite/manifest.json');
30
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
31
+ const entry = manifest['client/main.jsx'];
32
+ if (!entry) {
33
+ throw new Error(
34
+ 'Vite manifest has no "client/main.jsx" entry. Run the client build before starting the server.'
35
+ );
36
+ }
37
+ assets = {
38
+ js: entry.file,
39
+ css: entry.css ?? [],
40
+ imports: (entry.imports ?? []).map((key) => manifest[key]?.file).filter(Boolean),
41
+ };
42
+ return assets;
43
+ }
44
+
45
+ export default getAssets;
@@ -0,0 +1,79 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import appJson from '../../lib/build/app.js';
20
+ import lowdefyConfig from '../../lib/build/config.js';
21
+ import themeConfig from '../../lib/build/theme.js';
22
+ import getAssets from './getAssets.js';
23
+ import template from './template.js';
24
+
25
+ const basePath = lowdefyConfig.basePath ?? '';
26
+
27
+ // Replaces pages/[[...pageId]].js getServerSideProps and pages/404.js
28
+ // getStaticProps. The home redirect logic lives here, not at the route level.
29
+ async function renderPage(c, { pageId, status = 200 }) {
30
+ const context = c.get('lowdefyContext');
31
+ const { logger, session } = context;
32
+
33
+ let resolvedPageId = pageId;
34
+ const rootConfig = await getRootConfig(context);
35
+
36
+ if (!resolvedPageId) {
37
+ const { home } = rootConfig;
38
+ if (home.configured === false) {
39
+ logger.info({ event: 'redirect_to_homepage', pageId: home.pageId });
40
+ return c.redirect(`${basePath}/${home.pageId}`, 302);
41
+ }
42
+ resolvedPageId = home.pageId;
43
+ }
44
+
45
+ const pageConfig = await getPageConfig(context, {
46
+ pageId: resolvedPageId,
47
+ urlQuery: c.req.query(),
48
+ });
49
+
50
+ if (!pageConfig) {
51
+ if (resolvedPageId === '404') {
52
+ // No 404 page in the build — return a plain 404 rather than redirecting in a loop.
53
+ return c.text('Page not found.', 404);
54
+ }
55
+ logger.info({ event: 'redirect_page_not_found', pageId: resolvedPageId });
56
+ return c.redirect(`${basePath}/404`, 302);
57
+ }
58
+
59
+ logger.info({ event: 'page_view', pageId: resolvedPageId });
60
+
61
+ const html = template({
62
+ appendBody: appJson.html?.appendBody ?? '',
63
+ appendHead: appJson.html?.appendHead ?? '',
64
+ assets: getAssets(),
65
+ basePath,
66
+ config: {
67
+ basePath,
68
+ pageConfig,
69
+ rootConfig,
70
+ session: session ?? null,
71
+ },
72
+ themeConfig,
73
+ title: pageConfig.properties?.title ?? resolvedPageId,
74
+ });
75
+
76
+ return c.html(html, status);
77
+ }
78
+
79
+ export default renderPage;
@@ -0,0 +1,95 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import safeScriptJson from '../lib/safeScriptJson.js';
18
+
19
+ const HTML_ESCAPES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' };
20
+
21
+ function escapeHtml(value) {
22
+ return String(value).replace(/[&<>"]/g, (c) => HTML_ESCAPES[c]);
23
+ }
24
+
25
+ // Synchronous script that creates the @layer order declaration and keeps it as
26
+ // the first child of <head> via MutationObserver. antd's CSS-in-JS uses
27
+ // prependQueue to inject <style> tags at the top of <head>, which would
28
+ // otherwise make @layer antd the first (lowest priority) layer.
29
+ // MutationObserver fires before paint, so the browser never sees the wrong
30
+ // cascade order.
31
+ const layerOrderScript = `(function(){var s=document.createElement("style");s.id="__lf-layer-order";s.textContent="@layer theme, base, antd, components, utilities;";document.head.prepend(s);new MutationObserver(function(){if(document.head.firstChild!==s)document.head.prepend(s)}).observe(document.head,{childList:true})})();`;
32
+
33
+ // Synchronous pre-hydration script setting the <html> background and
34
+ // color-scheme — prevents a mode-mismatch flash of the page and of browser
35
+ // chrome (scrollbars, form controls) on page load. Mirrors useDarkMode.js
36
+ // resolution order: configDarkMode → localStorage → prefers-color-scheme.
37
+ function darkModeScript({ configColorMode, darkBg, lightBg }) {
38
+ return `(function(){var c=${safeScriptJson(configColorMode)};var db=${safeScriptJson(
39
+ darkBg
40
+ )};var lb=${safeScriptJson(
41
+ lightBg
42
+ )};var d;if(c==="dark")d=true;else if(c==="light")d=false;else{try{var p=localStorage.getItem("lowdefy_darkMode");if(p==="dark")d=true;else if(p==="light")d=false;else d=window.matchMedia("(prefers-color-scheme:dark)").matches}catch(e){d=window.matchMedia("(prefers-color-scheme:dark)").matches}}var bg=d?db:lb;document.documentElement.style.colorScheme=d?"dark":"light";if(bg)document.documentElement.style.backgroundColor=bg})();`;
43
+ }
44
+
45
+ function template({
46
+ appendBody = '',
47
+ appendHead = '',
48
+ assets,
49
+ basePath = '',
50
+ config,
51
+ themeConfig = {},
52
+ title,
53
+ }) {
54
+ const VALID_COLOR_MODES = ['system', 'light', 'dark'];
55
+ const configColorMode = VALID_COLOR_MODES.includes(themeConfig.darkMode)
56
+ ? themeConfig.darkMode
57
+ : 'system';
58
+ const darkBg = themeConfig?.antd?.darkToken?.colorBgLayout ?? '#000';
59
+ const lightBg = themeConfig?.antd?.lightToken?.colorBgLayout ?? '';
60
+
61
+ const cssLinks = assets.css
62
+ .map((file) => `<link rel="stylesheet" href="${basePath}/${file}" />`)
63
+ .join('\n ');
64
+ const modulePreloads = assets.imports
65
+ .map((file) => `<link rel="modulepreload" href="${basePath}/${file}" />`)
66
+ .join('\n ');
67
+
68
+ // appendHead and appendBody are intentionally raw HTML from app config
69
+ // (analytics snippets, font links) — they must not be escaped. The config
70
+ // JSON and pre-hydration interpolations go through safeScriptJson.
71
+ return `<!DOCTYPE html>
72
+ <html class="lowdefy">
73
+ <head>
74
+ <meta charset="utf-8" />
75
+ <script>${layerOrderScript}</script>
76
+ <script>${darkModeScript({ configColorMode, darkBg, lightBg })}</script>
77
+ <link rel="manifest" href="${basePath}/manifest.webmanifest" />
78
+ <link rel="icon" type="image/svg+xml" href="${basePath}/icon.svg" />
79
+ <link rel="apple-touch-icon" href="${basePath}/apple-touch-icon.png" />
80
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
81
+ ${title ? `<title>${escapeHtml(title)}</title>` : ''}
82
+ ${cssLinks}
83
+ ${modulePreloads}
84
+ ${appendHead}
85
+ </head>
86
+ <body>
87
+ <div id="root"></div>
88
+ <script id="__LOWDEFY_CONFIG__" type="application/json">${safeScriptJson(config)}</script>
89
+ ${appendBody}
90
+ <script type="module" src="${basePath}/${assets.js}"></script>
91
+ </body>
92
+ </html>`;
93
+ }
94
+
95
+ export default template;
package/src/index.js ADDED
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { serve } from '@hono/node-server';
18
+ import { WebSocketServer } from 'ws';
19
+
20
+ import createApp from './app.js';
21
+ import createLogger from '../lib/server/log/createLogger.js';
22
+
23
+ const app = createApp();
24
+ const logger = createLogger();
25
+ const port = Number(process.env.PORT ?? 3000);
26
+
27
+ const wss = new WebSocketServer({ noServer: true, maxPayload: 256 * 1024 });
28
+
29
+ const server = serve({ fetch: app.fetch, port, websocket: { server: wss } }, (info) => {
30
+ logger.info(`Lowdefy e2e server listening on http://localhost:${info.port}`);
31
+ });
32
+
33
+ function shutdown() {
34
+ server.close(() => {
35
+ process.exit(0);
36
+ });
37
+ }
38
+
39
+ process.on('SIGINT', shutdown);
40
+ process.on('SIGTERM', shutdown);
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ // Splits the rest of a catch-all route into decoded segments, independent of
18
+ // any configured basePath. Mirrors the Next.js [...param] query arrays —
19
+ // nested ids (slashes in pageId or endpointId) are real.
20
+ function getPathSegments(c, prefix) {
21
+ const rest = c.req.path.split(prefix)[1] ?? '';
22
+ return rest.split('/').filter(Boolean).map(decodeURIComponent);
23
+ }
24
+
25
+ export default getPathSegments;