@lowdefy/server-dev 4.0.0-alpha.6 → 4.0.0-alpha.9
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/next.config.js +6 -4
- package/package.json +36 -36
- package/src/components/App.js +0 -55
- package/src/components/Context.js +0 -62
- package/src/components/Head.js +0 -28
- package/src/components/LowdefyContext.js +0 -50
- package/src/components/Page.js +0 -54
- package/src/components/Reload.js +0 -43
- package/src/components/block/Block.js +0 -57
- package/src/components/block/CategorySwitch.js +0 -120
- package/src/components/block/Container.js +0 -87
- package/src/components/block/List.js +0 -94
- package/src/components/block/LoadingBlock.js +0 -22
- package/src/components/block/MountEvents.js +0 -46
- package/src/components/components.js +0 -25
- package/src/manager/BatchChanges.mjs +0 -66
- package/src/manager/getContext.mjs +0 -64
- package/src/manager/initialBuild.mjs +0 -24
- package/src/manager/processes/installPlugins.mjs +0 -36
- package/src/manager/processes/lowdefyBuild.mjs +0 -38
- package/src/manager/processes/nextBuild.mjs +0 -31
- package/src/manager/processes/reloadClients.mjs +0 -26
- package/src/manager/processes/startServer.mjs +0 -31
- package/src/manager/processes/startServerProcess.mjs +0 -34
- package/src/manager/run.mjs +0 -41
- package/src/manager/spawnProcess.mjs +0 -55
- package/src/manager/watchers/configWatcher.mjs +0 -28
- package/src/manager/watchers/envWatcher.mjs +0 -32
- package/src/manager/watchers/setupWatcher.mjs +0 -43
- package/src/manager/watchers/startWatchers.mjs +0 -64
- package/src/pages/404.js +0 -19
- package/src/pages/[pageId].js +0 -19
- package/src/pages/_app.js +0 -37
- package/src/pages/_document.js +0 -38
- package/src/pages/api/auth/[...nextauth].js +0 -28
- package/src/pages/api/page/[pageId].js +0 -29
- package/src/pages/api/ping.js +0 -19
- package/src/pages/api/reload.js +0 -52
- package/src/pages/api/request/[pageId]/[requestId].js +0 -44
- package/src/pages/api/root.js +0 -25
- package/src/pages/index.js +0 -19
- package/src/utils/callRequest.js +0 -27
- package/src/utils/request.js +0 -36
- package/src/utils/setPageId.js +0 -33
- package/src/utils/setupLink.js +0 -44
- package/src/utils/useMutateCache.js +0 -34
- package/src/utils/usePageConfig.js +0 -32
- package/src/utils/useRootConfig.js +0 -29
- package/src/utils/waitForRestartedServer.js +0 -32
|
@@ -1,32 +0,0 @@
|
|
|
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;
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
|
@@ -1,64 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/src/pages/[pageId].js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/src/pages/_app.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
package/src/pages/_document.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pages/api/ping.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pages/api/reload.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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;
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pages/api/root.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pages/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/src/utils/callRequest.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
package/src/utils/request.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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;
|
package/src/utils/setPageId.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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;
|
package/src/utils/setupLink.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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;
|
|
@@ -1,34 +0,0 @@
|
|
|
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;
|