@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,31 @@
|
|
|
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
|
+
/* eslint-disable no-console */
|
|
17
|
+
|
|
18
|
+
import startServerProcess from './startServerProcess.mjs';
|
|
19
|
+
|
|
20
|
+
async function startServer(context) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
context.serverProcessPromise = { resolve, reject };
|
|
23
|
+
try {
|
|
24
|
+
startServerProcess(context);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default startServer;
|
|
@@ -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 spawnProcess from '../spawnProcess.mjs';
|
|
18
|
+
|
|
19
|
+
function startServerProcess(context) {
|
|
20
|
+
context.serverProcess = spawnProcess({
|
|
21
|
+
logger: console,
|
|
22
|
+
command: context.packageManager,
|
|
23
|
+
args: ['run', 'next', 'start'],
|
|
24
|
+
silent: false,
|
|
25
|
+
});
|
|
26
|
+
context.serverProcess.on('exit', (code) => {
|
|
27
|
+
if (code !== 0) {
|
|
28
|
+
context.serverProcessPromise.reject(new Error('Server error.'));
|
|
29
|
+
}
|
|
30
|
+
context.serverProcessPromise.resolve();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default startServerProcess;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { wait } from '@lowdefy/helpers';
|
|
19
|
+
import opener from 'opener';
|
|
20
|
+
import getContext from './getContext.mjs';
|
|
21
|
+
import initialBuild from './initialBuild.mjs';
|
|
22
|
+
import startServer from './processes/startServer.mjs';
|
|
23
|
+
import startWatchers from './watchers/startWatchers.mjs';
|
|
24
|
+
|
|
25
|
+
async function run() {
|
|
26
|
+
const context = await getContext();
|
|
27
|
+
await initialBuild(context);
|
|
28
|
+
await startWatchers(context);
|
|
29
|
+
try {
|
|
30
|
+
const serverPromise = startServer(context);
|
|
31
|
+
await wait(800);
|
|
32
|
+
// TODO: set correct port
|
|
33
|
+
opener(`http://localhost:3000`);
|
|
34
|
+
await serverPromise;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
context.shutdownServer();
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
run();
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { spawn } from 'child_process';
|
|
18
|
+
|
|
19
|
+
function spawnProcess({ logger, command, args, processOptions, silent }) {
|
|
20
|
+
const process = spawn(command, args, processOptions);
|
|
21
|
+
|
|
22
|
+
process.stdout.on('data', (data) => {
|
|
23
|
+
if (!silent) {
|
|
24
|
+
data
|
|
25
|
+
.toString('utf8')
|
|
26
|
+
.split('\n')
|
|
27
|
+
.forEach((line) => {
|
|
28
|
+
if (line) {
|
|
29
|
+
logger.log(line);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
process.stderr.on('data', (data) => {
|
|
36
|
+
if (!silent) {
|
|
37
|
+
data
|
|
38
|
+
.toString('utf8')
|
|
39
|
+
.split('\n')
|
|
40
|
+
.forEach((line) => {
|
|
41
|
+
if (line) {
|
|
42
|
+
logger.warn(line);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
process.on('error', (error) => {
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return process;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default spawnProcess;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 setupWatcher from './setupWatcher.mjs';
|
|
18
|
+
|
|
19
|
+
async function configWatcher(context) {
|
|
20
|
+
const callback = async () => {
|
|
21
|
+
await context.lowdefyBuild();
|
|
22
|
+
context.reloadClients();
|
|
23
|
+
};
|
|
24
|
+
// TODO: Add ignored and watch paths
|
|
25
|
+
return setupWatcher({ callback, watchPaths: [context.directories.config] });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default configWatcher;
|
|
@@ -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 path from 'path';
|
|
18
|
+
import setupWatcher from './setupWatcher.mjs';
|
|
19
|
+
|
|
20
|
+
async function envWatcher(context) {
|
|
21
|
+
const callback = async () => {
|
|
22
|
+
console.log('.env file changed, restarting server...');
|
|
23
|
+
context.restartServer();
|
|
24
|
+
};
|
|
25
|
+
return setupWatcher({
|
|
26
|
+
callback,
|
|
27
|
+
watchPaths: [path.join(context.directories.config, '.env')],
|
|
28
|
+
watchDotfiles: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default envWatcher;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 chokidar from 'chokidar';
|
|
18
|
+
import BatchChanges from '../BatchChanges.mjs';
|
|
19
|
+
|
|
20
|
+
function setupWatcher({ callback, watchDotfiles = false, ignorePaths = [], watchPaths }) {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
// const { watch = [], watchIgnore = [] } = context.options;
|
|
23
|
+
// const resolvedWatchPaths = watch.map((pathName) => path.resolve(pathName));
|
|
24
|
+
|
|
25
|
+
const batchChanges = new BatchChanges({ fn: callback });
|
|
26
|
+
const defaultIgnorePaths = watchDotfiles
|
|
27
|
+
? []
|
|
28
|
+
: [
|
|
29
|
+
/(^|[/\\])\../, // ignore dotfiles
|
|
30
|
+
];
|
|
31
|
+
const configWatcher = chokidar.watch(watchPaths, {
|
|
32
|
+
ignored: [...defaultIgnorePaths, ...ignorePaths],
|
|
33
|
+
persistent: true,
|
|
34
|
+
ignoreInitial: true,
|
|
35
|
+
});
|
|
36
|
+
configWatcher.on('add', (...args) => batchChanges.newChange(args));
|
|
37
|
+
configWatcher.on('change', (...args) => batchChanges.newChange(args));
|
|
38
|
+
configWatcher.on('unlink', (...args) => batchChanges.newChange(args));
|
|
39
|
+
configWatcher.on('ready', () => resolve());
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default setupWatcher;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 configWatcher from './configWatcher.mjs';
|
|
18
|
+
import envWatcher from './envWatcher.mjs';
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
Config change
|
|
22
|
+
Watch <config-dir>, <watch-dirs>, !<ignore-dirs>
|
|
23
|
+
- Lowdefy build
|
|
24
|
+
- Trigger soft reload
|
|
25
|
+
----------------------------------------
|
|
26
|
+
Install new plugin
|
|
27
|
+
Watch <server>/package.json
|
|
28
|
+
|
|
29
|
+
- Install Server.
|
|
30
|
+
- Next build.
|
|
31
|
+
- No need for Lowdefy build (confirm?)
|
|
32
|
+
- Trigger hard reload
|
|
33
|
+
- Restart server.
|
|
34
|
+
|
|
35
|
+
----------------------------------------
|
|
36
|
+
.env change
|
|
37
|
+
Watch <config-dir>/.env
|
|
38
|
+
- Trigger hard reload
|
|
39
|
+
- Restart server.
|
|
40
|
+
----------------------------------------
|
|
41
|
+
Lowdefy version changed
|
|
42
|
+
Watch <config-dir>/lowdefy.yaml
|
|
43
|
+
- Warn and process.exit()
|
|
44
|
+
----------------------------------------
|
|
45
|
+
Style vars/app config change
|
|
46
|
+
Watch <server-dir>/build/app.json
|
|
47
|
+
Watch <server-dir>/build/config.json
|
|
48
|
+
- Next build.
|
|
49
|
+
- Trigger hard reload
|
|
50
|
+
- Restart server.
|
|
51
|
+
|
|
52
|
+
----------------------------------------
|
|
53
|
+
New plugin or icon used.
|
|
54
|
+
Watch <server-dir>/build/plugins/*
|
|
55
|
+
- Next build. (or dynamic import?)
|
|
56
|
+
- Trigger hard reload
|
|
57
|
+
- Restart server.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
async function startWatchers(context) {
|
|
61
|
+
await Promise.all([configWatcher(context), envWatcher(context)]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default startWatchers;
|
package/src/pages/404.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 App from '../components/App.js';
|
|
18
|
+
|
|
19
|
+
export default App;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 App from '../components/App.js';
|
|
18
|
+
|
|
19
|
+
export default App;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 React, { Suspense } from 'react';
|
|
18
|
+
|
|
19
|
+
import { ErrorBoundary } from '@lowdefy/block-utils';
|
|
20
|
+
|
|
21
|
+
import LowdefyContext from '../components/LowdefyContext.js';
|
|
22
|
+
|
|
23
|
+
import '../../build/plugins/styles.less';
|
|
24
|
+
|
|
25
|
+
function App({ Component, pageProps }) {
|
|
26
|
+
return (
|
|
27
|
+
<ErrorBoundary>
|
|
28
|
+
<Suspense>
|
|
29
|
+
<LowdefyContext>
|
|
30
|
+
{(lowdefy) => <Component lowdefy={lowdefy} {...pageProps} />}
|
|
31
|
+
</LowdefyContext>
|
|
32
|
+
</Suspense>
|
|
33
|
+
</ErrorBoundary>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default App;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 React from 'react';
|
|
18
|
+
import Document, { Html, Head, Main, NextScript } from 'next/document';
|
|
19
|
+
|
|
20
|
+
class LowdefyDocument extends Document {
|
|
21
|
+
render() {
|
|
22
|
+
return (
|
|
23
|
+
<Html>
|
|
24
|
+
<Head>
|
|
25
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
26
|
+
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
|
|
27
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
28
|
+
</Head>
|
|
29
|
+
<body>
|
|
30
|
+
<Main />
|
|
31
|
+
<NextScript />
|
|
32
|
+
</body>
|
|
33
|
+
</Html>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default LowdefyDocument;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 NextAuth from 'next-auth';
|
|
18
|
+
import Auth0Provider from 'next-auth/providers/auth0';
|
|
19
|
+
|
|
20
|
+
export default NextAuth({
|
|
21
|
+
providers: [
|
|
22
|
+
Auth0Provider({
|
|
23
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
24
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
25
|
+
issuer: process.env.AUTH0_ISSUER,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { createApiContext, getPageConfig } from '@lowdefy/api';
|
|
18
|
+
|
|
19
|
+
export default async function handler(req, res) {
|
|
20
|
+
const { pageId } = req.query;
|
|
21
|
+
// TODO: get the right api context options
|
|
22
|
+
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
23
|
+
const pageConfig = await getPageConfig(apiContext, { pageId });
|
|
24
|
+
if (pageConfig === null) {
|
|
25
|
+
res.status(404).send('Page not found.');
|
|
26
|
+
} else {
|
|
27
|
+
res.status(200).json(pageConfig);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export default async function handler(req, res) {
|
|
18
|
+
res.status(200).json({ timestamp: new Date().toISOString() });
|
|
19
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
// TODO: Send keep-alive comment event: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#examples
|
|
18
|
+
|
|
19
|
+
import chokidar from 'chokidar';
|
|
20
|
+
|
|
21
|
+
const handler = async (req, res) => {
|
|
22
|
+
res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
|
|
23
|
+
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
|
24
|
+
res.setHeader('X-Accel-Buffering', 'no');
|
|
25
|
+
res.setHeader('Connection', 'keep-alive');
|
|
26
|
+
|
|
27
|
+
const watcher = chokidar.watch(['./build/reload'], {
|
|
28
|
+
persistent: true,
|
|
29
|
+
ignoreInitial: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const reload = () => {
|
|
33
|
+
try {
|
|
34
|
+
res.write(`event: reload\ndata: ${JSON.stringify({})}\n\n`);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.log(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
watcher.on('add', () => reload());
|
|
40
|
+
watcher.on('change', () => reload());
|
|
41
|
+
watcher.on('unlink', () => reload());
|
|
42
|
+
|
|
43
|
+
// TODO: This isn't working.
|
|
44
|
+
req.on('close', () => {
|
|
45
|
+
console.log('req closed');
|
|
46
|
+
watcher.close().then(() => {
|
|
47
|
+
console.log('watcher closed');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default handler;
|
|
@@ -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 { callRequest, createApiContext } from '@lowdefy/api';
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
+
import connections from '../../../../../build/plugins/connections.js';
|
|
20
|
+
import operators from '../../../../../build/plugins/operatorsServer.js';
|
|
21
|
+
|
|
22
|
+
export default async function handler(req, res) {
|
|
23
|
+
try {
|
|
24
|
+
if (req.method !== 'POST') {
|
|
25
|
+
throw new Error('Only POST requests are supported.');
|
|
26
|
+
}
|
|
27
|
+
// TODO: configure API context
|
|
28
|
+
const apiContext = await createApiContext({
|
|
29
|
+
buildDirectory: './build',
|
|
30
|
+
connections,
|
|
31
|
+
// TODO: use a logger like pino
|
|
32
|
+
logger: console,
|
|
33
|
+
operators,
|
|
34
|
+
secrets: getSecretsFromEnv(),
|
|
35
|
+
});
|
|
36
|
+
const { pageId, requestId } = req.query;
|
|
37
|
+
const { payload } = req.body;
|
|
38
|
+
|
|
39
|
+
const response = await callRequest(apiContext, { pageId, payload, requestId });
|
|
40
|
+
res.status(200).json(response);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
res.status(500).json({ name: error.name, message: error.message });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { createApiContext, getRootConfig } from '@lowdefy/api';
|
|
18
|
+
|
|
19
|
+
export default async function handler(req, res) {
|
|
20
|
+
// TODO: get the right api context options
|
|
21
|
+
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
22
|
+
const rootConfig = await getRootConfig(apiContext);
|
|
23
|
+
|
|
24
|
+
res.status(200).json(rootConfig);
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 App from '../components/App.js';
|
|
18
|
+
|
|
19
|
+
export default App;
|