@lowdefy/server 4.0.0-rc.9 → 4.5.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.
- package/LICENSE +183 -183
- package/README.md +0 -21
- package/lib/{Page.js → client/Page.js} +7 -5
- package/lib/{auth → client/auth}/Auth.js +3 -2
- package/lib/{auth → client/auth}/AuthConfigured.js +3 -2
- package/lib/{auth → client/auth}/AuthNotConfigured.js +2 -1
- package/lib/client/createLogUsage.js +58 -0
- package/lib/server/apiWrapper.js +70 -0
- package/lib/server/auth/getAuthOptions.js +35 -0
- package/lib/{auth → server/auth}/getServerSession.js +4 -4
- package/lib/{fileCache.js → server/fileCache.js} +1 -1
- package/lib/server/log/createLogger.js +30 -0
- package/lib/server/log/logError.js +72 -0
- package/lib/server/log/logRequest.js +66 -0
- package/lib/server/serverSidePropsWrapper.js +60 -0
- package/lowdefy/build.mjs +16 -2
- package/lowdefy/createCustomPluginTypesMap.mjs +1 -1
- package/package.json +38 -35
- package/package.original.json +30 -25
- package/pages/404.js +10 -8
- package/pages/[pageId].js +14 -23
- package/pages/_app.js +22 -14
- package/pages/_document.js +1 -1
- package/pages/api/auth/[...nextauth].js +16 -29
- package/pages/api/endpoints/[endpointId].js +32 -0
- package/pages/api/request/[pageId]/[requestId].js +13 -34
- package/pages/api/usage.js +68 -0
- package/pages/index.js +13 -20
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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 { getNextAuthConfig } from '@lowdefy/api';
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
+
|
|
20
|
+
import adapters from '../../../build/plugins/auth/adapters.js';
|
|
21
|
+
import authJson from '../../../build/auth.json';
|
|
22
|
+
import callbacks from '../../../build/plugins/auth/callbacks.js';
|
|
23
|
+
import events from '../../../build/plugins/auth/events.js';
|
|
24
|
+
import providers from '../../../build/plugins/auth/providers.js';
|
|
25
|
+
|
|
26
|
+
function getAuthOptions({ logger }) {
|
|
27
|
+
return getNextAuthConfig({
|
|
28
|
+
authJson,
|
|
29
|
+
logger,
|
|
30
|
+
plugins: { adapters, callbacks, events, providers },
|
|
31
|
+
secrets: getSecretsFromEnv(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default getAuthOptions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { getServerSession as getNextAuthServerSession } from 'next-auth/next';
|
|
18
|
-
import { authOptions } from '../../pages/api/auth/[...nextauth].js';
|
|
19
|
-
import authJson from '../../build/auth.json';
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
import authJson from '../../../build/auth.json';
|
|
20
|
+
|
|
21
|
+
function getServerSession({ authOptions, req, res }) {
|
|
22
22
|
if (authJson.configured === true) {
|
|
23
23
|
return getNextAuthServerSession(req, res, authOptions);
|
|
24
24
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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 pino from 'pino';
|
|
18
|
+
|
|
19
|
+
// TODO: Pino does not serialize error.cause properties if the cause object is not an Error (or Error-like)
|
|
20
|
+
const logger = pino({
|
|
21
|
+
name: 'lowdefy_server',
|
|
22
|
+
level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
|
|
23
|
+
base: { pid: undefined, hostname: undefined },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function createLogger(metadata = {}) {
|
|
27
|
+
return logger.child(metadata);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default createLogger;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
function logError({ context, error }) {
|
|
18
|
+
try {
|
|
19
|
+
const { headers = {}, user = {} } = context;
|
|
20
|
+
|
|
21
|
+
context.logger.error({
|
|
22
|
+
// TODO:
|
|
23
|
+
// app_name
|
|
24
|
+
// app_version
|
|
25
|
+
// lowdefy_version
|
|
26
|
+
// build_hash
|
|
27
|
+
// config_hash
|
|
28
|
+
err: error,
|
|
29
|
+
user: {
|
|
30
|
+
id: user.id,
|
|
31
|
+
roles: user.roles,
|
|
32
|
+
sub: user.sub,
|
|
33
|
+
session_id: user.session_id,
|
|
34
|
+
},
|
|
35
|
+
url: context.req.url,
|
|
36
|
+
method: context.req.method,
|
|
37
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
38
|
+
hostname: context.req.hostname,
|
|
39
|
+
headers: {
|
|
40
|
+
'accept-language': headers['accept-language'],
|
|
41
|
+
'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
|
|
42
|
+
'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
|
|
43
|
+
'sec-ch-ua': headers['sec-ch-ua'],
|
|
44
|
+
'user-agent': headers['user-agent'],
|
|
45
|
+
host: headers.host,
|
|
46
|
+
referer: headers.referer,
|
|
47
|
+
// Non localhost headers
|
|
48
|
+
'x-forward-for': headers['x-forward-for'],
|
|
49
|
+
// Vercel headers
|
|
50
|
+
'x-vercel-id': headers['x-vercel-id'],
|
|
51
|
+
'x-real-ip': headers['x-real-ip'],
|
|
52
|
+
'x-vercel-ip-country': headers['x-vercel-ip-country'],
|
|
53
|
+
'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
|
|
54
|
+
'x-vercel-ip-city': headers['x-vercel-ip-city'],
|
|
55
|
+
'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
|
|
56
|
+
'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
|
|
57
|
+
'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
|
|
58
|
+
// Cloudflare headers
|
|
59
|
+
'cf-connecting-ip': headers['cf-connecting-ip'],
|
|
60
|
+
'cf-ray': headers['cf-ray'],
|
|
61
|
+
'cf-ipcountry': headers['cf-ipcountry'],
|
|
62
|
+
'cf-visitor': headers['cf-visitor'],
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
console.error('An error occurred while logging the error.');
|
|
68
|
+
console.error(e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default logError;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
// TODO: Better name needed here maybe?
|
|
18
|
+
function logRequest({ context }) {
|
|
19
|
+
const { headers = {}, user = {} } = context;
|
|
20
|
+
context.logger.info({
|
|
21
|
+
// TODO:
|
|
22
|
+
// app_name
|
|
23
|
+
// app_version
|
|
24
|
+
// lowdefy_version
|
|
25
|
+
// build_hash
|
|
26
|
+
// config_hash
|
|
27
|
+
user: {
|
|
28
|
+
id: user.id,
|
|
29
|
+
roles: user.roles,
|
|
30
|
+
sub: user.sub,
|
|
31
|
+
session_id: user.session_id, // TODO: Implement session id
|
|
32
|
+
},
|
|
33
|
+
url: context.req.url,
|
|
34
|
+
method: context.req.method,
|
|
35
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
36
|
+
hostname: context.req.hostname,
|
|
37
|
+
headers: {
|
|
38
|
+
'accept-language': headers['accept-language'],
|
|
39
|
+
'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
|
|
40
|
+
'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
|
|
41
|
+
'sec-ch-ua': headers['sec-ch-ua'],
|
|
42
|
+
'user-agent': headers['user-agent'],
|
|
43
|
+
host: headers.host,
|
|
44
|
+
referer: headers.referer,
|
|
45
|
+
'x-forward-for': headers['x-forward-for'],
|
|
46
|
+
// Vercel headers
|
|
47
|
+
'x-vercel-id': headers['x-vercel-id'],
|
|
48
|
+
'x-real-ip': headers['x-real-ip'],
|
|
49
|
+
'x-vercel-ip-country': headers['x-vercel-ip-country'],
|
|
50
|
+
'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
|
|
51
|
+
'x-vercel-ip-city': headers['x-vercel-ip-city'],
|
|
52
|
+
'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
|
|
53
|
+
'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
|
|
54
|
+
'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
|
|
55
|
+
// Cloudflare headers
|
|
56
|
+
'cf-connecting-ip': headers['cf-connecting-ip'],
|
|
57
|
+
'cf-ray': headers['cf-ray'],
|
|
58
|
+
'cf-ipcountry': headers['cf-ipcountry'],
|
|
59
|
+
'cf-visitor': headers['cf-visitor'],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
// TODO:
|
|
63
|
+
// Next local? nextContext.locale, nextContext.locales, nextContext.defaultLocale
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default logRequest;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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 path from 'path';
|
|
18
|
+
import crypto from 'crypto';
|
|
19
|
+
import { createApiContext } from '@lowdefy/api';
|
|
20
|
+
|
|
21
|
+
import config from '../../build/config.json';
|
|
22
|
+
import createLogger from './log/createLogger.js';
|
|
23
|
+
import fileCache from './fileCache.js';
|
|
24
|
+
import getServerSession from './auth/getServerSession.js';
|
|
25
|
+
import logError from './log/logError.js';
|
|
26
|
+
import logRequest from './log/logRequest.js';
|
|
27
|
+
import getAuthOptions from './auth/getAuthOptions.js';
|
|
28
|
+
|
|
29
|
+
// TODO: Merge serverSidePropsWrapper and apiWrapper?
|
|
30
|
+
function serverSidePropsWrapper(handler) {
|
|
31
|
+
return async function wrappedHandler(nextContext) {
|
|
32
|
+
const context = {
|
|
33
|
+
// Important to give absolute path so Next can trace build files
|
|
34
|
+
rid: crypto.randomUUID(),
|
|
35
|
+
buildDirectory: path.join(process.cwd(), 'build'),
|
|
36
|
+
config,
|
|
37
|
+
fileCache,
|
|
38
|
+
headers: nextContext?.req?.headers,
|
|
39
|
+
logger: console,
|
|
40
|
+
nextContext,
|
|
41
|
+
req: nextContext?.req,
|
|
42
|
+
res: nextContext?.res,
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
context.logger = createLogger({ rid: context.rid });
|
|
46
|
+
context.authOptions = getAuthOptions(context);
|
|
47
|
+
context.session = await getServerSession(context);
|
|
48
|
+
createApiContext(context);
|
|
49
|
+
logRequest({ context });
|
|
50
|
+
// Await here so that if handler throws it is caught.
|
|
51
|
+
const response = await handler({ context, nextContext });
|
|
52
|
+
return response;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
logError({ error, context });
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default serverSidePropsWrapper;
|
package/lowdefy/build.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
|
-
Copyright 2020-
|
|
3
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
4
4
|
|
|
5
5
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
you may not use this file except in compliance with the License.
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import path from 'path';
|
|
19
|
+
import pino from 'pino';
|
|
19
20
|
import yargs from 'yargs';
|
|
20
21
|
import { hideBin } from 'yargs/helpers';
|
|
21
22
|
|
|
@@ -37,10 +38,23 @@ async function run() {
|
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
const customTypesMap = await createCustomPluginTypesMap({ directories });
|
|
41
|
+
|
|
42
|
+
const logger = pino({
|
|
43
|
+
name: 'lowdefy_build',
|
|
44
|
+
level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
|
|
45
|
+
base: { pid: undefined, hostname: undefined },
|
|
46
|
+
mixin: (context, level) => {
|
|
47
|
+
return {
|
|
48
|
+
...context,
|
|
49
|
+
print: context.print ?? logger.levels.labels[level],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
40
54
|
await build({
|
|
41
55
|
customTypesMap,
|
|
42
56
|
directories,
|
|
43
|
-
logger
|
|
57
|
+
logger,
|
|
44
58
|
refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
|
|
45
59
|
});
|
|
46
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -35,47 +35,50 @@
|
|
|
35
35
|
".eslintrc.yaml",
|
|
36
36
|
".npmrc"
|
|
37
37
|
],
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "cp package.json package.original.json || copy package.json package.original.json",
|
|
40
|
-
"build:lowdefy": "node lowdefy/build.mjs",
|
|
41
|
-
"build:next": "next build",
|
|
42
|
-
"dev": "next dev",
|
|
43
|
-
"start": "next start",
|
|
44
|
-
"lint": "next lint",
|
|
45
|
-
"next": "next"
|
|
46
|
-
},
|
|
47
38
|
"dependencies": {
|
|
48
|
-
"@lowdefy/actions-core": "4.
|
|
49
|
-
"@lowdefy/api": "4.
|
|
50
|
-
"@lowdefy/
|
|
51
|
-
"@lowdefy/blocks-
|
|
52
|
-
"@lowdefy/blocks-
|
|
53
|
-
"@lowdefy/
|
|
54
|
-
"@lowdefy/
|
|
55
|
-
"@lowdefy/
|
|
56
|
-
"@lowdefy/
|
|
57
|
-
"@lowdefy/
|
|
58
|
-
"@lowdefy/
|
|
59
|
-
"next": "
|
|
60
|
-
"next
|
|
39
|
+
"@lowdefy/actions-core": "4.5.0",
|
|
40
|
+
"@lowdefy/api": "4.5.0",
|
|
41
|
+
"@lowdefy/block-utils": "4.5.0",
|
|
42
|
+
"@lowdefy/blocks-antd": "4.5.0",
|
|
43
|
+
"@lowdefy/blocks-basic": "4.5.0",
|
|
44
|
+
"@lowdefy/blocks-loaders": "4.5.0",
|
|
45
|
+
"@lowdefy/client": "4.5.0",
|
|
46
|
+
"@lowdefy/helpers": "4.5.0",
|
|
47
|
+
"@lowdefy/layout": "4.5.0",
|
|
48
|
+
"@lowdefy/node-utils": "4.5.0",
|
|
49
|
+
"@lowdefy/operators-js": "4.5.0",
|
|
50
|
+
"@lowdefy/plugin-next-auth": "4.5.0",
|
|
51
|
+
"next": "13.5.4",
|
|
52
|
+
"next-auth": "4.24.5",
|
|
53
|
+
"pino": "8.16.2",
|
|
61
54
|
"process": "0.11.10",
|
|
62
55
|
"react": "18.2.0",
|
|
63
56
|
"react-dom": "18.2.0",
|
|
64
|
-
"react-icons": "4.
|
|
57
|
+
"react-icons": "4.12.0"
|
|
65
58
|
},
|
|
66
59
|
"devDependencies": {
|
|
67
|
-
"@lowdefy/build": "4.
|
|
68
|
-
"@next/eslint-plugin-next": "
|
|
69
|
-
"less": "4.
|
|
70
|
-
"less-loader": "11.1.
|
|
71
|
-
"next-with-less": "
|
|
72
|
-
"webpack": "5.
|
|
73
|
-
"yaml": "2.
|
|
74
|
-
"yargs": "17.
|
|
60
|
+
"@lowdefy/build": "4.5.0",
|
|
61
|
+
"@next/eslint-plugin-next": "13.5.4",
|
|
62
|
+
"less": "4.2.0",
|
|
63
|
+
"less-loader": "11.1.3",
|
|
64
|
+
"next-with-less": "3.0.1",
|
|
65
|
+
"webpack": "5.94.0",
|
|
66
|
+
"yaml": "2.3.4",
|
|
67
|
+
"yargs": "17.7.2"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=18"
|
|
75
71
|
},
|
|
76
|
-
"packageManager": "pnpm@7.11.0",
|
|
77
72
|
"publishConfig": {
|
|
78
73
|
"access": "public"
|
|
79
74
|
},
|
|
80
|
-
"
|
|
81
|
-
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "cp package.json package.original.json || copy package.json package.original.json",
|
|
77
|
+
"build:lowdefy": "node lowdefy/build.mjs",
|
|
78
|
+
"build:next": "next build",
|
|
79
|
+
"dev": "next dev",
|
|
80
|
+
"start": "next start",
|
|
81
|
+
"lint": "next lint",
|
|
82
|
+
"next": "next"
|
|
83
|
+
}
|
|
84
|
+
}
|
package/package.original.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -42,38 +42,43 @@
|
|
|
42
42
|
"dev": "next dev",
|
|
43
43
|
"start": "next start",
|
|
44
44
|
"lint": "next lint",
|
|
45
|
-
"next": "next"
|
|
45
|
+
"next": "next",
|
|
46
|
+
"prepublishOnly": "pnpm build"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@lowdefy/actions-core": "4.
|
|
49
|
-
"@lowdefy/api": "4.
|
|
50
|
-
"@lowdefy/
|
|
51
|
-
"@lowdefy/blocks-
|
|
52
|
-
"@lowdefy/blocks-
|
|
53
|
-
"@lowdefy/
|
|
54
|
-
"@lowdefy/
|
|
55
|
-
"@lowdefy/
|
|
56
|
-
"@lowdefy/
|
|
57
|
-
"@lowdefy/
|
|
58
|
-
"@lowdefy/
|
|
59
|
-
"next": "
|
|
60
|
-
"next
|
|
49
|
+
"@lowdefy/actions-core": "4.5.0",
|
|
50
|
+
"@lowdefy/api": "4.5.0",
|
|
51
|
+
"@lowdefy/block-utils": "4.5.0",
|
|
52
|
+
"@lowdefy/blocks-antd": "4.5.0",
|
|
53
|
+
"@lowdefy/blocks-basic": "4.5.0",
|
|
54
|
+
"@lowdefy/blocks-loaders": "4.5.0",
|
|
55
|
+
"@lowdefy/client": "4.5.0",
|
|
56
|
+
"@lowdefy/helpers": "4.5.0",
|
|
57
|
+
"@lowdefy/layout": "4.5.0",
|
|
58
|
+
"@lowdefy/node-utils": "4.5.0",
|
|
59
|
+
"@lowdefy/operators-js": "4.5.0",
|
|
60
|
+
"@lowdefy/plugin-next-auth": "4.5.0",
|
|
61
|
+
"next": "13.5.4",
|
|
62
|
+
"next-auth": "4.24.5",
|
|
63
|
+
"pino": "8.16.2",
|
|
61
64
|
"process": "0.11.10",
|
|
62
65
|
"react": "18.2.0",
|
|
63
66
|
"react-dom": "18.2.0",
|
|
64
|
-
"react-icons": "4.
|
|
67
|
+
"react-icons": "4.12.0"
|
|
65
68
|
},
|
|
66
69
|
"devDependencies": {
|
|
67
|
-
"@lowdefy/build": "4.
|
|
68
|
-
"@next/eslint-plugin-next": "
|
|
69
|
-
"less": "4.
|
|
70
|
-
"less-loader": "11.1.
|
|
71
|
-
"next-with-less": "
|
|
72
|
-
"webpack": "5.
|
|
73
|
-
"yaml": "2.
|
|
74
|
-
"yargs": "17.
|
|
70
|
+
"@lowdefy/build": "4.5.0",
|
|
71
|
+
"@next/eslint-plugin-next": "13.5.4",
|
|
72
|
+
"less": "4.2.0",
|
|
73
|
+
"less-loader": "11.1.3",
|
|
74
|
+
"next-with-less": "3.0.1",
|
|
75
|
+
"webpack": "5.94.0",
|
|
76
|
+
"yaml": "2.3.4",
|
|
77
|
+
"yargs": "17.7.2"
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=18"
|
|
75
81
|
},
|
|
76
|
-
"packageManager": "pnpm@7.11.0",
|
|
77
82
|
"publishConfig": {
|
|
78
83
|
"access": "public"
|
|
79
84
|
}
|
package/pages/404.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,25 +13,27 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import path from 'path';
|
|
17
18
|
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
18
19
|
|
|
19
20
|
import config from '../build/config.json';
|
|
20
|
-
import fileCache from '../lib/fileCache.js';
|
|
21
|
-
import Page from '../lib/Page.js';
|
|
21
|
+
import fileCache from '../lib/server/fileCache.js';
|
|
22
|
+
import Page from '../lib/client/Page.js';
|
|
22
23
|
|
|
23
24
|
export async function getStaticProps() {
|
|
24
25
|
// Important to give absolute path so Next can trace build files
|
|
25
|
-
const
|
|
26
|
+
const context = {
|
|
26
27
|
buildDirectory: path.join(process.cwd(), 'build'),
|
|
27
28
|
config,
|
|
28
29
|
fileCache,
|
|
29
|
-
logger: console,
|
|
30
|
-
}
|
|
30
|
+
logger: console, // TODO: pino or console or 🤷♂️?
|
|
31
|
+
};
|
|
32
|
+
createApiContext(context);
|
|
31
33
|
|
|
32
34
|
const [rootConfig, pageConfig] = await Promise.all([
|
|
33
|
-
getRootConfig(
|
|
34
|
-
getPageConfig(
|
|
35
|
+
getRootConfig(context),
|
|
36
|
+
getPageConfig(context, { pageId: '404' }),
|
|
35
37
|
]);
|
|
36
38
|
|
|
37
39
|
return {
|
package/pages/[pageId].js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,32 +14,21 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
19
|
-
|
|
20
|
-
import config from '../build/config.json';
|
|
21
|
-
import fileCache from '../lib/fileCache.js';
|
|
22
|
-
import getServerSession from '../lib/auth/getServerSession.js';
|
|
23
|
-
import Page from '../lib/Page.js';
|
|
24
|
-
|
|
25
|
-
export async function getServerSideProps(context) {
|
|
26
|
-
const { pageId } = context.params;
|
|
27
|
-
const session = await getServerSession(context);
|
|
28
|
-
// Important to give absolute path so Next can trace build files
|
|
29
|
-
const apiContext = createApiContext({
|
|
30
|
-
buildDirectory: path.join(process.cwd(), 'build'),
|
|
31
|
-
config,
|
|
32
|
-
fileCache,
|
|
33
|
-
logger: console,
|
|
34
|
-
session,
|
|
35
|
-
});
|
|
17
|
+
import { getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
36
18
|
|
|
19
|
+
import serverSidePropsWrapper from '../lib/server/serverSidePropsWrapper.js';
|
|
20
|
+
import Page from '../lib/client/Page.js';
|
|
21
|
+
|
|
22
|
+
async function getServerSidePropsHandler({ context, nextContext }) {
|
|
23
|
+
const { pageId } = nextContext.params;
|
|
24
|
+
const { logger, session } = context;
|
|
37
25
|
const [rootConfig, pageConfig] = await Promise.all([
|
|
38
|
-
getRootConfig(
|
|
39
|
-
getPageConfig(
|
|
26
|
+
getRootConfig(context),
|
|
27
|
+
getPageConfig(context, { pageId }),
|
|
40
28
|
]);
|
|
41
29
|
|
|
42
30
|
if (!pageConfig) {
|
|
31
|
+
logger.info({ event: 'redirect_page_not_found', pageId });
|
|
43
32
|
return {
|
|
44
33
|
redirect: {
|
|
45
34
|
destination: '/404',
|
|
@@ -47,7 +36,7 @@ export async function getServerSideProps(context) {
|
|
|
47
36
|
},
|
|
48
37
|
};
|
|
49
38
|
}
|
|
50
|
-
|
|
39
|
+
logger.info({ event: 'page_view', pageId });
|
|
51
40
|
return {
|
|
52
41
|
props: {
|
|
53
42
|
pageConfig,
|
|
@@ -57,4 +46,6 @@ export async function getServerSideProps(context) {
|
|
|
57
46
|
};
|
|
58
47
|
}
|
|
59
48
|
|
|
49
|
+
export const getServerSideProps = serverSidePropsWrapper(getServerSidePropsHandler);
|
|
50
|
+
|
|
60
51
|
export default Page;
|