@lowdefy/server-dev 4.0.0-alpha.9 → 4.0.0-rc.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/.npmrc +1 -0
- package/lib/App.js +67 -0
- package/lib/Page.js +50 -0
- package/lib/Reload.js +52 -0
- package/lib/RestartingPage.js +47 -0
- package/lib/auth/Auth.js +35 -0
- package/lib/auth/AuthConfigured.js +47 -0
- package/lib/auth/AuthNotConfigured.js +32 -0
- package/lib/auth/getServerSession.js +28 -0
- package/lib/fileCache.js +20 -0
- package/lib/setPageId.js +30 -0
- package/lib/utils/request.js +38 -0
- package/lib/utils/useMutateCache.js +34 -0
- package/lib/utils/usePageConfig.js +27 -0
- package/lib/utils/useRootConfig.js +26 -0
- package/lib/utils/waitForRestartedServer.js +38 -0
- package/manager/getContext.mjs +77 -0
- package/manager/processes/initialBuild.mjs +27 -0
- package/manager/processes/installPlugins.mjs +31 -0
- package/manager/processes/lowdefyBuild.mjs +34 -0
- package/manager/processes/nextBuild.mjs +31 -0
- package/manager/processes/readDotEnv.mjs +26 -0
- package/manager/processes/reloadClients.mjs +26 -0
- package/manager/processes/restartServer.mjs +28 -0
- package/manager/processes/shutdownServer.mjs +35 -0
- package/manager/processes/startServer.mjs +45 -0
- package/manager/processes/startWatchers.mjs +31 -0
- package/manager/run.mjs +109 -0
- package/manager/utils/BatchChanges.mjs +64 -0
- package/manager/utils/createCustomPluginTypesMap.mjs +72 -0
- package/manager/utils/createLogger.mjs +34 -0
- package/manager/utils/getLowdefyVersion.mjs +51 -0
- package/manager/utils/getNextBin.mjs +36 -0
- package/manager/utils/setupWatcher.mjs +50 -0
- package/manager/watchers/envWatcher.mjs +35 -0
- package/manager/watchers/lowdefyBuildWatcher.mjs +55 -0
- package/manager/watchers/nextBuildWatcher.mjs +99 -0
- package/next.config.js +2 -7
- package/package.json +46 -37
- package/pages/404.js +19 -0
- package/pages/[pageId].js +19 -0
- package/pages/_app.js +37 -0
- package/pages/_document.js +50 -0
- package/pages/api/auth/[...nextauth].js +45 -0
- package/pages/api/page/[pageId].js +40 -0
- package/pages/api/ping.js +19 -0
- package/pages/api/reload.js +50 -0
- package/pages/api/request/[pageId]/[requestId].js +50 -0
- package/pages/api/root.js +35 -0
- package/pages/index.js +19 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 chokidar from 'chokidar';
|
|
18
|
+
|
|
19
|
+
const handler = async (req, res) => {
|
|
20
|
+
res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
|
|
21
|
+
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
|
22
|
+
res.setHeader('X-Accel-Buffering', 'no');
|
|
23
|
+
res.setHeader('Connection', 'keep-alive');
|
|
24
|
+
|
|
25
|
+
const watcher = chokidar.watch(['./build/reload'], {
|
|
26
|
+
persistent: true,
|
|
27
|
+
ignoreInitial: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const reload = () => {
|
|
31
|
+
try {
|
|
32
|
+
res.write(`event: reload\ndata: ${JSON.stringify({})}\n\n`);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.log(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
watcher.on('add', () => reload());
|
|
38
|
+
watcher.on('change', () => reload());
|
|
39
|
+
watcher.on('unlink', () => reload());
|
|
40
|
+
|
|
41
|
+
// TODO: This isn't working.
|
|
42
|
+
req.on('close', () => {
|
|
43
|
+
console.log('req closed');
|
|
44
|
+
watcher.close().then(() => {
|
|
45
|
+
console.log('watcher closed');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default handler;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { callRequest, createApiContext } from '@lowdefy/api';
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
+
|
|
20
|
+
import config from '../../../../build/config.json';
|
|
21
|
+
import connections from '../../../../build/plugins/connections.js';
|
|
22
|
+
import fileCache from '../../../../lib/fileCache.js';
|
|
23
|
+
import getServerSession from '../../../../lib/auth/getServerSession.js';
|
|
24
|
+
import operators from '../../../../build/plugins/operators/server.js';
|
|
25
|
+
|
|
26
|
+
export default async function handler(req, res) {
|
|
27
|
+
try {
|
|
28
|
+
if (req.method !== 'POST') {
|
|
29
|
+
throw new Error('Only POST requests are supported.');
|
|
30
|
+
}
|
|
31
|
+
const session = await getServerSession({ req, res });
|
|
32
|
+
const apiContext = createApiContext({
|
|
33
|
+
buildDirectory: './build',
|
|
34
|
+
config,
|
|
35
|
+
connections,
|
|
36
|
+
fileCache,
|
|
37
|
+
logger: console,
|
|
38
|
+
operators,
|
|
39
|
+
secrets: getSecretsFromEnv(),
|
|
40
|
+
session,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const { blockId, pageId, requestId } = req.query;
|
|
44
|
+
const { payload } = req.body;
|
|
45
|
+
const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
|
|
46
|
+
res.status(200).json(response);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
res.status(500).json({ name: error.name, message: error.message });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { createApiContext, getRootConfig } from '@lowdefy/api';
|
|
18
|
+
|
|
19
|
+
import config from '../../build/config.json';
|
|
20
|
+
import fileCache from '../../lib/fileCache.js';
|
|
21
|
+
import getServerSession from '../../lib/auth/getServerSession.js';
|
|
22
|
+
|
|
23
|
+
export default async function handler(req, res) {
|
|
24
|
+
const session = await getServerSession({ req, res });
|
|
25
|
+
const apiContext = createApiContext({
|
|
26
|
+
buildDirectory: './build',
|
|
27
|
+
config,
|
|
28
|
+
fileCache,
|
|
29
|
+
logger: console,
|
|
30
|
+
session,
|
|
31
|
+
});
|
|
32
|
+
const rootConfig = await getRootConfig(apiContext);
|
|
33
|
+
|
|
34
|
+
res.status(200).json(rootConfig);
|
|
35
|
+
}
|
package/pages/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 App from '../lib/App.js';
|
|
18
|
+
|
|
19
|
+
export default App;
|