@lowdefy/server-e2e 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260720135014
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/.eslintrc.yaml +1 -0
- package/lib/build/app.js +1 -8
- package/lib/build/appMeta.js +1 -8
- package/lib/build/auth.js +1 -8
- package/lib/build/config.js +1 -8
- package/lib/build/logger.js +1 -8
- package/lib/build/theme.js +1 -8
- package/lib/client/Page.js +57 -0
- package/{src/lib/getPathSegments.js → lib/client/auth/Auth.js} +22 -7
- package/lib/server/apiWrapper.js +80 -0
- package/lib/server/auth/{getUser.js → getServerSession.js} +7 -10
- package/lib/server/log/logRequest.js +3 -1
- package/lib/server/serverSidePropsWrapper.js +64 -0
- package/lowdefy/createCustomPluginTypesMap.mjs +2 -3
- package/lowdefy/createCustomPluginTypesMap.test.mjs +0 -2
- package/next.config.js +20 -0
- package/package.json +41 -50
- package/package.original.json +49 -53
- package/pages/404.js +49 -0
- package/pages/[[...pageId]].js +85 -0
- package/{client/App.jsx → pages/_app.js} +30 -45
- package/pages/_document.js +106 -0
- package/{src/routes/sessionMock.js → pages/api/auth/session.js} +5 -7
- package/{src/routes/clientError.js → pages/api/client-error.js} +18 -14
- package/{src/routes/endpoints.js → pages/api/endpoints/[...endpointId].js} +7 -8
- package/{src/routes/request.js → pages/api/request/[...path].js} +10 -10
- package/{src/routes → pages/api}/usage.js +8 -11
- package/client/Page.jsx +0 -93
- package/client/main.jsx +0 -39
- package/lib/build/i18n.js +0 -26
- package/lib/client/auth/Auth.jsx +0 -69
- package/postcss.config.cjs +0 -1
- package/src/app.js +0 -80
- package/src/html/getAssets.js +0 -45
- package/src/html/renderPage.js +0 -78
- package/src/html/template.js +0 -94
- package/src/index.js +0 -40
- package/src/lib/safeScriptJson.js +0 -38
- package/src/middleware/apiContext.js +0 -87
- package/src/middleware/errorHandler.js +0 -45
- package/src/routes/apiPage.js +0 -35
- package/src/routes/user.js +0 -27
- package/src/routes/websocket.js +0 -46
- package/vite.config.js +0 -45
|
@@ -14,23 +14,20 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
import
|
|
17
|
+
import packageJson from '../../package.json';
|
|
18
|
+
import apiWrapper from '../../lib/server/apiWrapper.js';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async function usageHandler(c) {
|
|
23
|
-
if (c.req.method !== 'POST') {
|
|
20
|
+
async function handler({ context, req, res }) {
|
|
21
|
+
if (req.method !== 'POST') {
|
|
24
22
|
throw new Error('Only POST requests are supported.');
|
|
25
23
|
}
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const host = c.req.header('host');
|
|
24
|
+
const { user, machine } = req.body;
|
|
25
|
+
const host = req.headers.host;
|
|
29
26
|
context.logger.info({ event: 'log_usage', user, machine });
|
|
30
27
|
|
|
31
28
|
const timestamp = Date.now();
|
|
32
29
|
|
|
33
|
-
return
|
|
30
|
+
return res.status(200).json({
|
|
34
31
|
offline: false,
|
|
35
32
|
data: {
|
|
36
33
|
gitSha: context.appMeta.gitSha,
|
|
@@ -43,4 +40,4 @@ async function usageHandler(c) {
|
|
|
43
40
|
});
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
export default
|
|
43
|
+
export default apiWrapper(handler);
|
package/client/Page.jsx
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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 React, { useEffect, useRef, useState } from 'react';
|
|
18
|
-
|
|
19
|
-
import Client from '@lowdefy/client';
|
|
20
|
-
import createRouter from '@lowdefy/client/adapters/createRouter.js';
|
|
21
|
-
import createLinkComponent from '@lowdefy/client/adapters/Link.js';
|
|
22
|
-
import Head from '@lowdefy/client/adapters/Head.js';
|
|
23
|
-
|
|
24
|
-
import actions from '../build/plugins/actions.js';
|
|
25
|
-
import blockMetas from '../build/plugins/blockMetas.json';
|
|
26
|
-
import blocks from '../build/plugins/blocks.js';
|
|
27
|
-
import icons from '../build/plugins/icons.js';
|
|
28
|
-
import operators from '../build/plugins/operators/client.js';
|
|
29
|
-
import jsMap from '../build/plugins/operators/clientJsMap.js';
|
|
30
|
-
|
|
31
|
-
// Replaces lib/client/Page.js. The first page renders from the config
|
|
32
|
-
// embedded in the HTML; SPA navigations fetch /api/page/* and swap pageConfig.
|
|
33
|
-
function Page({ auth, config, lowdefy }) {
|
|
34
|
-
const [pageConfig, setPageConfig] = useState(config.pageConfig);
|
|
35
|
-
|
|
36
|
-
const routerRef = useRef(null);
|
|
37
|
-
if (!routerRef.current) {
|
|
38
|
-
const router = createRouter({ basePath: config.basePath ?? '', window });
|
|
39
|
-
routerRef.current = {
|
|
40
|
-
router,
|
|
41
|
-
Link: createLinkComponent({ router }),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const { router, Link } = routerRef.current;
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
const unsubscribe = router.subscribe(async ({ pageId }) => {
|
|
48
|
-
const targetPageId = pageId ?? config.rootConfig.home.pageId;
|
|
49
|
-
try {
|
|
50
|
-
const res = await fetch(`${router.basePath}/api/page/${targetPageId}`);
|
|
51
|
-
if (!res.ok) {
|
|
52
|
-
if (targetPageId !== '404') {
|
|
53
|
-
router.replace({ pathname: '/404' });
|
|
54
|
-
}
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const { pageConfig: nextPageConfig } = await res.json();
|
|
58
|
-
setPageConfig(nextPageConfig);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
// Network failure on SPA navigation — fall back to a full page load.
|
|
61
|
-
window.location.assign(
|
|
62
|
-
`${router.basePath}/${targetPageId === config.rootConfig.home.pageId ? '' : targetPageId}`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return unsubscribe;
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<Client
|
|
71
|
-
auth={auth}
|
|
72
|
-
Components={{ Head, Link }}
|
|
73
|
-
config={{
|
|
74
|
-
pageConfig,
|
|
75
|
-
rootConfig: config.rootConfig,
|
|
76
|
-
}}
|
|
77
|
-
jsMap={jsMap}
|
|
78
|
-
lowdefy={lowdefy}
|
|
79
|
-
router={router}
|
|
80
|
-
stage="e2e"
|
|
81
|
-
types={{
|
|
82
|
-
actions,
|
|
83
|
-
blockMetas,
|
|
84
|
-
blocks,
|
|
85
|
-
icons,
|
|
86
|
-
operators,
|
|
87
|
-
}}
|
|
88
|
-
window={window}
|
|
89
|
-
/>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default Page;
|
package/client/main.jsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
// CSS layer order — MUST be the first CSS import. This locks the cascade
|
|
18
|
-
// priority (antd > base/preflight) before antd's StyleProvider injects
|
|
19
|
-
// @layer antd {} at runtime.
|
|
20
|
-
import '../build/layer-order.css';
|
|
21
|
-
|
|
22
|
-
import React from 'react';
|
|
23
|
-
import { createRoot } from 'react-dom/client';
|
|
24
|
-
|
|
25
|
-
import App from './App.jsx';
|
|
26
|
-
|
|
27
|
-
import '../build/globals.css';
|
|
28
|
-
|
|
29
|
-
const config = JSON.parse(document.getElementById('__LOWDEFY_CONFIG__').textContent);
|
|
30
|
-
const container = document.getElementById('root');
|
|
31
|
-
|
|
32
|
-
// Keep one React root across Vite HMR updates — re-running createRoot on a
|
|
33
|
-
// container that already has a root is an error.
|
|
34
|
-
const root = import.meta.hot?.data.root ?? createRoot(container);
|
|
35
|
-
if (import.meta.hot) {
|
|
36
|
-
import.meta.hot.data.root = root;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
root.render(<App config={config} />);
|
package/lib/build/i18n.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
// Build artifacts are read from disk because the Hono server runs as
|
|
18
|
-
// unbundled Node.js ESM — JSON imports would need import attributes, and
|
|
19
|
-
// client code imports the build JSON directly through Vite instead.
|
|
20
|
-
import fs from 'node:fs';
|
|
21
|
-
import path from 'node:path';
|
|
22
|
-
import { serializer } from '@lowdefy/helpers';
|
|
23
|
-
|
|
24
|
-
const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/i18n.json'), 'utf8'));
|
|
25
|
-
|
|
26
|
-
export default serializer.deserialize(raw);
|
package/lib/client/auth/Auth.jsx
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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 { serializer } from '@lowdefy/helpers';
|
|
18
|
-
|
|
19
|
-
import rawAuthConfig from '../../../build/auth.json';
|
|
20
|
-
|
|
21
|
-
const authConfig = serializer.deserialize(rawAuthConfig);
|
|
22
|
-
|
|
23
|
-
function e2eNotSupported() {
|
|
24
|
-
throw new Error('Sign-in and sign-out are not supported in e2e testing.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function Auth({ children, user }) {
|
|
28
|
-
const auth = {
|
|
29
|
-
authConfig,
|
|
30
|
-
user,
|
|
31
|
-
// Matches the BetterAuth client contract: { data, error }.
|
|
32
|
-
getSession: async () => {
|
|
33
|
-
const res = await fetch('/api/auth/session');
|
|
34
|
-
if (res.ok) {
|
|
35
|
-
return { data: await res.json(), error: null };
|
|
36
|
-
}
|
|
37
|
-
return { data: null, error: null };
|
|
38
|
-
},
|
|
39
|
-
getResolvedUser: async () => {
|
|
40
|
-
const res = await fetch('/api/user');
|
|
41
|
-
if (res.ok) {
|
|
42
|
-
return res.json();
|
|
43
|
-
}
|
|
44
|
-
return { user: null };
|
|
45
|
-
},
|
|
46
|
-
acceptInvitation: e2eNotSupported,
|
|
47
|
-
addPasskey: e2eNotSupported,
|
|
48
|
-
changePassword: e2eNotSupported,
|
|
49
|
-
deletePasskey: e2eNotSupported,
|
|
50
|
-
requestPasswordReset: e2eNotSupported,
|
|
51
|
-
resetPassword: e2eNotSupported,
|
|
52
|
-
revokeOtherSessions: e2eNotSupported,
|
|
53
|
-
sendVerificationEmail: e2eNotSupported,
|
|
54
|
-
setActiveOrganization: e2eNotSupported,
|
|
55
|
-
signInEmail: e2eNotSupported,
|
|
56
|
-
signInMagicLink: e2eNotSupported,
|
|
57
|
-
signInOauth2: e2eNotSupported,
|
|
58
|
-
signInSocial: e2eNotSupported,
|
|
59
|
-
signOut: e2eNotSupported,
|
|
60
|
-
signUpEmail: e2eNotSupported,
|
|
61
|
-
twoFactorDisable: e2eNotSupported,
|
|
62
|
-
twoFactorEnable: e2eNotSupported,
|
|
63
|
-
twoFactorVerifyBackupCode: e2eNotSupported,
|
|
64
|
-
twoFactorVerifyTotp: e2eNotSupported,
|
|
65
|
-
};
|
|
66
|
-
return children(auth);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default Auth;
|
package/postcss.config.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = { plugins: { '@tailwindcss/postcss': {} } };
|
package/src/app.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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 userHandler from './routes/user.js';
|
|
33
|
-
import websocketHandler from './routes/websocket.js';
|
|
34
|
-
|
|
35
|
-
const basePath = lowdefyConfig.basePath ?? '';
|
|
36
|
-
|
|
37
|
-
function createApp() {
|
|
38
|
-
const app = basePath ? new Hono().basePath(basePath) : new Hono();
|
|
39
|
-
const logger = createLogger({ server: 'lowdefy' });
|
|
40
|
-
|
|
41
|
-
app.use('*', async (c, next) => {
|
|
42
|
-
if (c.req.path.includes('/api/websocket')) {
|
|
43
|
-
return next();
|
|
44
|
-
}
|
|
45
|
-
return compress()(c, next);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
app.use('/api/*', apiContext());
|
|
49
|
-
// Mock session endpoint — reads the lowdefy_e2e_user cookie; also the
|
|
50
|
-
// e2e harness health check (e2e-utils polls /api/auth/session).
|
|
51
|
-
app.get('/api/auth/session', sessionMockHandler);
|
|
52
|
-
app.all('/api/request/*', requestHandler);
|
|
53
|
-
app.all('/api/endpoints/*', endpointsHandler);
|
|
54
|
-
app.all('/api/client-error', clientErrorHandler);
|
|
55
|
-
app.all('/api/usage', usageHandler);
|
|
56
|
-
app.get('/api/websocket', websocketHandler);
|
|
57
|
-
app.get('/api/page/*', apiPageHandler);
|
|
58
|
-
app.get('/api/user', userHandler);
|
|
59
|
-
|
|
60
|
-
// Vite build output (includes public/ via Vite's publicDir copy). Falls
|
|
61
|
-
// through to the page routes when no file matches.
|
|
62
|
-
app.use(
|
|
63
|
-
'/*',
|
|
64
|
-
serveStatic({
|
|
65
|
-
root: './dist/client',
|
|
66
|
-
rewriteRequestPath: basePath ? (path) => path.replace(basePath, '') : undefined,
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
app.use('/*', apiContext());
|
|
71
|
-
app.get('/', (c) => renderPage(c, { pageId: '' }));
|
|
72
|
-
app.get('/404', (c) => renderPage(c, { pageId: '404', status: 404 }));
|
|
73
|
-
app.get('/:rest{.+}', (c) => renderPage(c, { pageId: c.req.param('rest') }));
|
|
74
|
-
|
|
75
|
-
app.onError(createErrorHandler({ basePath, logger }));
|
|
76
|
-
|
|
77
|
-
return app;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default createApp;
|
package/src/html/getAssets.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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;
|
package/src/html/renderPage.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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, user } = 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 result = await getPageConfig(context, { pageId: resolvedPageId });
|
|
46
|
-
|
|
47
|
-
if (result.status !== 'ok') {
|
|
48
|
-
if (resolvedPageId === '404') {
|
|
49
|
-
// No 404 page in the build — return a plain 404 rather than redirecting in a loop.
|
|
50
|
-
return c.text('Page not found.', 404);
|
|
51
|
-
}
|
|
52
|
-
logger.info({ event: 'redirect_page_not_found', pageId: resolvedPageId });
|
|
53
|
-
return c.redirect(`${basePath}/404`, 302);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const { pageConfig } = result;
|
|
57
|
-
|
|
58
|
-
logger.info({ event: 'page_view', pageId: resolvedPageId });
|
|
59
|
-
|
|
60
|
-
const html = template({
|
|
61
|
-
appendBody: appJson.html?.appendBody ?? '',
|
|
62
|
-
appendHead: appJson.html?.appendHead ?? '',
|
|
63
|
-
assets: getAssets(),
|
|
64
|
-
basePath,
|
|
65
|
-
config: {
|
|
66
|
-
basePath,
|
|
67
|
-
pageConfig,
|
|
68
|
-
rootConfig,
|
|
69
|
-
user: user ?? null,
|
|
70
|
-
},
|
|
71
|
-
themeConfig,
|
|
72
|
-
title: pageConfig.properties?.title ?? resolvedPageId,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return c.html(html, status);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default renderPage;
|
package/src/html/template.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
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 = { '&': '&', '<': '<', '>': '>', '"': '"' };
|
|
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 background script — prevents mode-mismatch flash
|
|
34
|
-
// on page load. Mirrors useDarkMode.js resolution order:
|
|
35
|
-
// configDarkMode → localStorage → prefers-color-scheme.
|
|
36
|
-
function darkModeScript({ configColorMode, darkBg, lightBg }) {
|
|
37
|
-
return `(function(){var c=${safeScriptJson(configColorMode)};var db=${safeScriptJson(
|
|
38
|
-
darkBg
|
|
39
|
-
)};var lb=${safeScriptJson(
|
|
40
|
-
lightBg
|
|
41
|
-
)};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;if(bg)document.documentElement.style.backgroundColor=bg})();`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function template({
|
|
45
|
-
appendBody = '',
|
|
46
|
-
appendHead = '',
|
|
47
|
-
assets,
|
|
48
|
-
basePath = '',
|
|
49
|
-
config,
|
|
50
|
-
themeConfig = {},
|
|
51
|
-
title,
|
|
52
|
-
}) {
|
|
53
|
-
const VALID_COLOR_MODES = ['system', 'light', 'dark'];
|
|
54
|
-
const configColorMode = VALID_COLOR_MODES.includes(themeConfig.darkMode)
|
|
55
|
-
? themeConfig.darkMode
|
|
56
|
-
: 'system';
|
|
57
|
-
const darkBg = themeConfig?.antd?.darkToken?.colorBgLayout ?? '#000';
|
|
58
|
-
const lightBg = themeConfig?.antd?.lightToken?.colorBgLayout ?? '';
|
|
59
|
-
|
|
60
|
-
const cssLinks = assets.css
|
|
61
|
-
.map((file) => `<link rel="stylesheet" href="${basePath}/${file}" />`)
|
|
62
|
-
.join('\n ');
|
|
63
|
-
const modulePreloads = assets.imports
|
|
64
|
-
.map((file) => `<link rel="modulepreload" href="${basePath}/${file}" />`)
|
|
65
|
-
.join('\n ');
|
|
66
|
-
|
|
67
|
-
// appendHead and appendBody are intentionally raw HTML from app config
|
|
68
|
-
// (analytics snippets, font links) — they must not be escaped. The config
|
|
69
|
-
// JSON and pre-hydration interpolations go through safeScriptJson.
|
|
70
|
-
return `<!DOCTYPE html>
|
|
71
|
-
<html class="lowdefy">
|
|
72
|
-
<head>
|
|
73
|
-
<meta charset="utf-8" />
|
|
74
|
-
<script>${layerOrderScript}</script>
|
|
75
|
-
<script>${darkModeScript({ configColorMode, darkBg, lightBg })}</script>
|
|
76
|
-
<link rel="manifest" href="${basePath}/manifest.webmanifest" />
|
|
77
|
-
<link rel="icon" type="image/svg+xml" href="${basePath}/icon.svg" />
|
|
78
|
-
<link rel="apple-touch-icon" href="${basePath}/apple-touch-icon.png" />
|
|
79
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
80
|
-
${title ? `<title>${escapeHtml(title)}</title>` : ''}
|
|
81
|
-
${cssLinks}
|
|
82
|
-
${modulePreloads}
|
|
83
|
-
${appendHead}
|
|
84
|
-
</head>
|
|
85
|
-
<body>
|
|
86
|
-
<div id="root"></div>
|
|
87
|
-
<script id="__LOWDEFY_CONFIG__" type="application/json">${safeScriptJson(config)}</script>
|
|
88
|
-
${appendBody}
|
|
89
|
-
<script type="module" src="${basePath}/${assets.js}"></script>
|
|
90
|
-
</body>
|
|
91
|
-
</html>`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default template;
|
package/src/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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);
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
// Escape characters that could break out of the enclosing <script> tag or
|
|
18
|
-
// terminate a JS string literal. Used to defuse the js/bad-code-sanitization
|
|
19
|
-
// class of injection for values embedded into inline scripts and the
|
|
20
|
-
// application/json config script.
|
|
21
|
-
const SCRIPT_ESCAPES = {
|
|
22
|
-
'<': '\\u003C',
|
|
23
|
-
'>': '\\u003E',
|
|
24
|
-
'\b': '\\b',
|
|
25
|
-
'\f': '\\f',
|
|
26
|
-
'\n': '\\n',
|
|
27
|
-
'\r': '\\r',
|
|
28
|
-
'\t': '\\t',
|
|
29
|
-
'\0': '\\0',
|
|
30
|
-
'\u2028': '\\u2028',
|
|
31
|
-
'\u2029': '\\u2029',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
function safeScriptJson(value) {
|
|
35
|
-
return JSON.stringify(value).replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, (c) => SCRIPT_ESCAPES[c]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default safeScriptJson;
|