@lowdefy/server-dev 3.23.0-alpha.0 → 4.0.0-alpha.6
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/README.md +0 -24
- package/next.config.js +34 -0
- package/package.json +46 -34
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +17 -0
- package/public/logo-dark-theme.png +0 -0
- package/public/logo-light-theme.png +0 -0
- package/public/logo-square-dark-theme.png +0 -0
- package/public/logo-square-light-theme.png +0 -0
- package/public/manifest.webmanifest +16 -0
- package/src/components/App.js +55 -0
- package/src/components/Context.js +62 -0
- package/src/components/Head.js +28 -0
- package/src/components/LowdefyContext.js +50 -0
- package/src/components/Page.js +54 -0
- package/src/components/Reload.js +43 -0
- package/src/components/block/Block.js +57 -0
- package/src/components/block/CategorySwitch.js +120 -0
- package/src/components/block/Container.js +87 -0
- package/src/components/block/List.js +94 -0
- package/src/components/block/LoadingBlock.js +22 -0
- package/src/components/block/MountEvents.js +46 -0
- package/src/components/components.js +25 -0
- package/src/manager/BatchChanges.mjs +66 -0
- package/src/manager/getContext.mjs +64 -0
- package/src/manager/initialBuild.mjs +24 -0
- package/src/manager/processes/installPlugins.mjs +36 -0
- package/src/manager/processes/lowdefyBuild.mjs +38 -0
- package/src/manager/processes/nextBuild.mjs +31 -0
- package/src/manager/processes/reloadClients.mjs +26 -0
- package/src/manager/processes/startServer.mjs +31 -0
- package/src/manager/processes/startServerProcess.mjs +34 -0
- package/src/manager/run.mjs +41 -0
- package/src/manager/spawnProcess.mjs +55 -0
- package/src/manager/watchers/configWatcher.mjs +28 -0
- package/src/manager/watchers/envWatcher.mjs +32 -0
- package/src/manager/watchers/setupWatcher.mjs +43 -0
- package/src/manager/watchers/startWatchers.mjs +64 -0
- package/src/pages/404.js +19 -0
- package/src/pages/[pageId].js +19 -0
- package/src/pages/_app.js +37 -0
- package/src/pages/_document.js +38 -0
- package/src/pages/api/auth/[...nextauth].js +28 -0
- package/src/pages/api/page/[pageId].js +29 -0
- package/src/pages/api/ping.js +19 -0
- package/src/pages/api/reload.js +52 -0
- package/src/pages/api/request/[pageId]/[requestId].js +44 -0
- package/src/pages/api/root.js +25 -0
- package/src/pages/index.js +19 -0
- package/src/utils/callRequest.js +27 -0
- package/src/utils/request.js +36 -0
- package/src/utils/setPageId.js +33 -0
- package/src/utils/setupLink.js +44 -0
- package/src/utils/useMutateCache.js +34 -0
- package/src/utils/usePageConfig.js +32 -0
- package/src/utils/useRootConfig.js +29 -0
- package/src/utils/waitForRestartedServer.js +32 -0
- package/dist/server.js +0 -47
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 request from './request.js';
|
|
18
|
+
|
|
19
|
+
function callRequest({ pageId, payload, requestId }) {
|
|
20
|
+
return request({
|
|
21
|
+
url: `/api/request/${pageId}/${requestId}`,
|
|
22
|
+
method: 'POST',
|
|
23
|
+
body: { payload },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default callRequest;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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
|
+
async function request({ url, method = 'GET', body }) {
|
|
18
|
+
const res = await fetch(url, {
|
|
19
|
+
method,
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
},
|
|
23
|
+
body: body && JSON.stringify(body),
|
|
24
|
+
});
|
|
25
|
+
if (res.status === 404) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
// TODO: check
|
|
30
|
+
const body = await res.json();
|
|
31
|
+
throw new Error(body.message || 'Request error');
|
|
32
|
+
}
|
|
33
|
+
return res.json();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default request;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 setPageId(lowdefy) {
|
|
18
|
+
if (lowdefy._internal.pathname === '/404') {
|
|
19
|
+
lowdefy.pageId = '404';
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (!lowdefy._internal.query.pageId) {
|
|
23
|
+
lowdefy.pageId = lowdefy.home.pageId;
|
|
24
|
+
if (lowdefy.home.configured === false) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
lowdefy.pageId = lowdefy._internal.query.pageId;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default setPageId;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 { createLink } from '@lowdefy/engine';
|
|
18
|
+
|
|
19
|
+
function setupLink({ lowdefy }) {
|
|
20
|
+
const { router, window } = lowdefy._internal;
|
|
21
|
+
const sameOriginLink = (path, newTab) => {
|
|
22
|
+
if (newTab) {
|
|
23
|
+
return window.open(`${window.location.origin}${lowdefy.basePath}${path}`, '_blank').focus();
|
|
24
|
+
} else {
|
|
25
|
+
// Next handles the basePath here.
|
|
26
|
+
return router.push({
|
|
27
|
+
pathname: path,
|
|
28
|
+
// TODO: Do we handle urlQuery as a param here?
|
|
29
|
+
// query: {},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const newOriginLink = (path, newTab) => {
|
|
34
|
+
if (newTab) {
|
|
35
|
+
return window.open(path, '_blank').focus();
|
|
36
|
+
} else {
|
|
37
|
+
return (window.location.href = path);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const backLink = () => window.history.back();
|
|
41
|
+
return createLink({ backLink, lowdefy, newOriginLink, sameOriginLink });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default setupLink;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 { useSWRConfig } from 'swr';
|
|
18
|
+
|
|
19
|
+
function useMutateCache() {
|
|
20
|
+
const { cache, mutate } = useSWRConfig();
|
|
21
|
+
return () => {
|
|
22
|
+
const keys = ['/api/root'];
|
|
23
|
+
|
|
24
|
+
for (const key of cache.keys()) {
|
|
25
|
+
if (key.startsWith('/api/page')) {
|
|
26
|
+
keys.push(key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const mutations = keys.map((key) => mutate(key));
|
|
30
|
+
return Promise.all(mutations);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default useMutateCache;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import useSWR from 'swr';
|
|
15
|
+
|
|
16
|
+
import request from './request.js';
|
|
17
|
+
|
|
18
|
+
// TODO: Handle TokenExpiredError
|
|
19
|
+
|
|
20
|
+
function fetchPageConfig(url) {
|
|
21
|
+
return request({ url });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function usePageConfig(pageId) {
|
|
25
|
+
if (!pageId) {
|
|
26
|
+
pageId = 'NULL';
|
|
27
|
+
}
|
|
28
|
+
const { data } = useSWR(`/api/page/${pageId}`, fetchPageConfig, { suspense: true });
|
|
29
|
+
return { data };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default usePageConfig;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import useSWR from 'swr';
|
|
15
|
+
|
|
16
|
+
import request from './request.js';
|
|
17
|
+
|
|
18
|
+
// TODO: Handle TokenExpiredError
|
|
19
|
+
|
|
20
|
+
function fetchRootConfig() {
|
|
21
|
+
return request({ url: '/api/root' });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function useRootConfig() {
|
|
25
|
+
const { data } = useSWR('root', fetchRootConfig, { suspense: true });
|
|
26
|
+
return { data };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default useRootConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 request from './request.js';
|
|
18
|
+
|
|
19
|
+
function waitForRestartedServer(lowdefy) {
|
|
20
|
+
setTimeout(async () => {
|
|
21
|
+
try {
|
|
22
|
+
await request({
|
|
23
|
+
url: '/api/ping',
|
|
24
|
+
});
|
|
25
|
+
lowdefy._internal.window.location.reload();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
waitForRestartedServer(lowdefy);
|
|
28
|
+
}
|
|
29
|
+
}, 1500);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default waitForRestartedServer;
|
package/dist/server.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
4
|
-
|
|
5
|
-
var _server = _interopRequireDefault(require("@lowdefy/server"));
|
|
6
|
-
|
|
7
|
-
var _shell = require("@lowdefy/shell");
|
|
8
|
-
|
|
9
|
-
var _nodeUtils = require("@lowdefy/node-utils");
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
Copyright 2020-2021 Lowdefy, Inc
|
|
15
|
-
|
|
16
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
17
|
-
you may not use this file except in compliance with the License.
|
|
18
|
-
You may obtain a copy of the License at
|
|
19
|
-
|
|
20
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
-
|
|
22
|
-
Unless required by applicable law or agreed to in writing, software
|
|
23
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
-
See the License for the specific language governing permissions and
|
|
26
|
-
limitations under the License.
|
|
27
|
-
*/
|
|
28
|
-
_dotenv.default.config({
|
|
29
|
-
silent: true
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
var buildDirectory = process.env.LOWDEFY_SERVER_BUILD_DIRECTORY || './.lowdefy/build';
|
|
33
|
-
var publicDirectory = process.env.LOWDEFY_SERVER_PUBLIC_DIRECTORY || _shell.publicDirectory;
|
|
34
|
-
var port = parseInt(process.env.LOWDEFY_SERVER_PORT) || 3000;
|
|
35
|
-
var serverBasePath = process.env.LOWDEFY_SERVER_BASE_PATH || '';
|
|
36
|
-
var server = (0, _server.default)({
|
|
37
|
-
buildDirectory,
|
|
38
|
-
development: true,
|
|
39
|
-
getSecrets: (0, _nodeUtils.createGetSecretsFromEnv)(),
|
|
40
|
-
logger: console,
|
|
41
|
-
publicDirectory,
|
|
42
|
-
serverBasePath,
|
|
43
|
-
shellDirectory: _shell.shellDirectory
|
|
44
|
-
});
|
|
45
|
-
server.listen({
|
|
46
|
-
port
|
|
47
|
-
}, () => console.log("\uD83D\uDE80 Server ready at http://localhost:".concat(port).concat(serverBasePath !== '' ? "/".concat(serverBasePath) : serverBasePath)));
|