@lowdefy/server-dev 4.0.0-alpha.22 → 4.0.0-alpha.25

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.
@@ -14,12 +14,13 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { getSession } from 'next-auth/react';
17
+ import { unstable_getServerSession } from 'next-auth/next';
18
+ import { authOptions } from '../../pages/api/auth/[...nextauth].js';
18
19
  import authJson from '../../build/auth.json';
19
20
 
20
- async function getServerSession(context) {
21
+ async function getServerSession({ req, res }) {
21
22
  if (authJson.configured === true) {
22
- return await getSession(context);
23
+ return await unstable_getServerSession(req, res, authOptions);
23
24
  }
24
25
  return undefined;
25
26
  }
@@ -13,13 +13,13 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
17
  import path from 'path';
19
18
 
20
19
  import yargs from 'yargs';
21
20
  import { hideBin } from 'yargs/helpers';
22
21
 
22
+ import createLogger from './utils/createLogger.mjs';
23
23
  import initialBuild from './processes/initialBuild.mjs';
24
24
  import installPlugins from './processes/installPlugins.mjs';
25
25
  import lowdefyBuild from './processes/lowdefyBuild.mjs';
@@ -46,6 +46,7 @@ async function getContext() {
46
46
  config: path.resolve(argv.configDirectory || env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
47
47
  server: process.cwd(),
48
48
  },
49
+ logger: createLogger({ level: env.LOWDEFY_LOG_LEVEL }),
49
50
  options: {
50
51
  port: argv.port || env.PORT || 3000,
51
52
  refResolver: argv.refResolver || env.LOWDEFY_BUILD_REF_RESOLVER,
@@ -55,8 +56,6 @@ async function getContext() {
55
56
  argv.watchIgnore || env.LOWDEFY_SERVER_DEV_WATCH_IGNORE
56
57
  ? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH_IGNORE)
57
58
  : [],
58
- // TODO: read option from env
59
- verbose: argv.verbose || false,
60
59
  },
61
60
  packageManager: argv.packageManager || env.LOWDEFY_PACKAGE_MANAGER || 'npm',
62
61
  version: env.npm_package_version,
@@ -21,15 +21,15 @@ const args = {
21
21
  yarn: ['install'],
22
22
  };
23
23
 
24
- function installPlugins({ packageManager, packageManagerCmd, options }) {
24
+ function installPlugins({ logger, packageManager, packageManagerCmd }) {
25
25
  return async () => {
26
- console.log('Installing plugins...');
26
+ logger.info({ print: 'spin' }, 'Installing plugins...');
27
27
  await spawnProcess({
28
- logger: console,
29
28
  command: packageManagerCmd,
30
29
  args: args[packageManager],
31
- silent: !options.verbose,
30
+ stdOutLineHandler: (line) => logger.debug(line),
32
31
  });
32
+ logger.info({ print: 'log' }, 'Installed plugins.');
33
33
  };
34
34
  }
35
35
 
@@ -17,16 +17,17 @@
17
17
  import build from '@lowdefy/build';
18
18
  import createCustomPluginTypesMap from '../utils/createCustomPluginTypesMap.mjs';
19
19
 
20
- function lowdefyBuild({ directories, options }) {
20
+ function lowdefyBuild({ directories, logger, options }) {
21
21
  return async () => {
22
22
  const customTypesMap = await createCustomPluginTypesMap({ directories });
23
23
  await build({
24
24
  customTypesMap,
25
25
  directories,
26
- logger: console,
26
+ logger,
27
27
  refResolver: options.refResolver,
28
28
  stage: 'dev',
29
29
  });
30
+ logger.info({ print: 'log' }, 'Built config.');
30
31
  };
31
32
  }
32
33
 
@@ -16,15 +16,15 @@
16
16
 
17
17
  import { spawnProcess } from '@lowdefy/node-utils';
18
18
 
19
- function nextBuild({ bin, options }) {
19
+ function nextBuild({ bin, logger }) {
20
20
  return async () => {
21
- console.log('Building app...');
21
+ logger.info({ print: 'spin' }, 'Building app...');
22
22
  await spawnProcess({
23
- logger: console,
24
23
  command: 'node',
25
24
  args: [bin.next, 'build'],
26
- silent: !options.verbose,
25
+ stdOutLineHandler: (line) => logger.debug(line),
27
26
  });
27
+ logger.info({ print: 'log' }, 'Built app.');
28
28
  };
29
29
  }
30
30
 
@@ -14,13 +14,14 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import startNextServer from './startNextServer.mjs';
17
+ import startServer from './startServer.mjs';
18
18
 
19
19
  function restartServer(context) {
20
20
  return () => {
21
- context.shutdownServer(); // Is this needed here?
22
- console.log('Restarting server...');
23
- startNextServer(context);
21
+ context.shutdownServer();
22
+ context.logger.info({ print: 'spin' }, 'Restarting server...');
23
+ startServer(context);
24
+ context.logger.info({ print: 'succeed' }, 'Restarted server.');
24
25
  };
25
26
  }
26
27
 
@@ -17,15 +17,15 @@
17
17
  function shutdownServer(context) {
18
18
  return () => {
19
19
  if (context.nextServer) {
20
- // console.log(
21
- // `Existing server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
22
- // );
20
+ context.logger.debug(
21
+ `Existing next server with pid ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
22
+ );
23
23
  if (!context.nextServer.killed) {
24
- console.log('Shutting down server...');
24
+ context.logger.info({ print: 'spin' }, 'Shutting down server...');
25
25
  context.nextServer.kill();
26
- // console.log(
27
- // `Killed server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
28
- // );
26
+ context.logger.debug(
27
+ `Killed next server with pid ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
28
+ );
29
29
  }
30
30
  context.nextServer = null;
31
31
  }
@@ -13,19 +13,33 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
- import startNextServer from './startNextServer.mjs';
17
+ import { spawnProcess } from '@lowdefy/node-utils';
19
18
 
20
- async function startServer(context) {
21
- return new Promise((resolve, reject) => {
22
- try {
23
- startNextServer(context);
24
- } catch (error) {
25
- console.log(error);
26
- reject(error);
27
- }
19
+ function startServer(context) {
20
+ context.shutdownServer();
21
+
22
+ const nextServer = spawnProcess({
23
+ stdOutLineHandler: (line) => context.logger.info({ print: 'log' }, line),
24
+ stdErrLineHandler: (line) => context.logger.error(line),
25
+ command: 'node',
26
+ args: [context.bin.next, 'start'],
27
+ processOptions: {
28
+ env: {
29
+ ...process.env,
30
+ PORT: context.options.port,
31
+ },
32
+ },
33
+ returnProcess: true,
34
+ });
35
+ context.logger.debug(`Started next server with pid ${nextServer.pid}.`);
36
+ nextServer.on('exit', (code, signal) => {
37
+ context.logger.debug(`nextServer exit ${nextServer.pid}, signal: ${signal}, code: ${code}`);
38
+ });
39
+ nextServer.on('error', (error) => {
40
+ context.logger.error(error);
28
41
  });
42
+ context.nextServer = nextServer;
29
43
  }
30
44
 
31
45
  export default startServer;
package/manager/run.mjs CHANGED
@@ -73,23 +73,32 @@ The run script does the following:
73
73
  pinging the /api/ping route, until it detects a new server has started, and then reloads the window.
74
74
  */
75
75
 
76
- async function run() {
77
- const context = await getContext();
78
- await context.initialBuild();
79
- await context.startWatchers();
76
+ /* TODO:
77
+ Not killing server on errors properly
78
+ when:
79
+ - initial build fails
80
+ */
81
+
82
+ const context = await getContext();
83
+
84
+ try {
80
85
  try {
81
- const serverPromise = startServer(context);
82
- await wait(800);
83
- if (process.env.LOWDEFY_SERVER_DEV_OPEN_BROWSER === 'true') {
84
- // TODO: Wait 1 sec for a ping and don't open if a ping is seen
85
- opener(`http://localhost:${context.options.port}`);
86
- }
87
- await serverPromise;
86
+ await context.initialBuild();
88
87
  } catch (error) {
89
- console.log(error);
90
- context.shutdownServer();
91
- throw error;
88
+ context.logger.error(error);
92
89
  }
93
- }
94
90
 
95
- run();
91
+ await context.startWatchers();
92
+
93
+ startServer(context);
94
+ await wait(800);
95
+ if (process.env.LOWDEFY_SERVER_DEV_OPEN_BROWSER === 'true') {
96
+ // TODO: Wait 1 sec for a ping and don't open if a ping is seen
97
+ opener(`http://localhost:${context.options.port}`);
98
+ }
99
+ await new Promise(() => {});
100
+ } catch (error) {
101
+ context.logger.error(error);
102
+ context.shutdownServer();
103
+ process.exit();
104
+ }
@@ -13,24 +13,22 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
17
  import { type } from '@lowdefy/helpers';
19
18
 
20
19
  class BatchChanges {
21
- constructor({ fn, minDelay }) {
20
+ constructor({ context, fn, delay }) {
21
+ this.context = context;
22
22
  this._call = this._call.bind(this);
23
23
  this.args = [];
24
- this.delay = minDelay || 500;
24
+ this.delay = delay || 500;
25
25
  this.fn = fn;
26
- this.minDelay = minDelay || 500;
27
26
  this.repeat = false;
28
27
  this.running = false;
29
28
  }
30
29
 
31
30
  newChange(...args) {
32
31
  this.args.push(args.filter((arg) => type.isString(arg))); // filter for string paths since chokidar also returns an stats object on windows.
33
- this.delay = this.minDelay;
34
32
  this._startTimer();
35
33
  }
36
34
 
@@ -58,10 +56,7 @@ class BatchChanges {
58
56
  }
59
57
  } catch (error) {
60
58
  this.running = false;
61
- console.error(error);
62
- this.delay *= 2;
63
- console.warn(`Retrying in ${this.delay / 1000}s.`);
64
- this._startTimer();
59
+ this.context.logger.error(error?.message ?? error);
65
60
  }
66
61
  }
67
62
  }
@@ -34,6 +34,7 @@ async function createCustomPluginTypesMap({ directories }) {
34
34
  const customTypesMap = {
35
35
  actions: {},
36
36
  auth: {
37
+ adapters: {},
37
38
  callbacks: {},
38
39
  events: {},
39
40
  providers: {},
@@ -0,0 +1,34 @@
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
+ import pino from 'pino';
17
+
18
+ function createLogger({ level = 'info' }) {
19
+ const logger = pino({
20
+ name: 'lowdefy build',
21
+ level,
22
+ base: { pid: undefined, hostname: undefined },
23
+ // TODO: Add log as custom level
24
+ mixin: (context, level) => {
25
+ return {
26
+ ...context,
27
+ print: context.print ?? logger.levels.labels[level],
28
+ };
29
+ },
30
+ });
31
+ return logger;
32
+ }
33
+
34
+ export default createLogger;
@@ -19,6 +19,7 @@ import BatchChanges from './BatchChanges.mjs';
19
19
 
20
20
  function setupWatcher({
21
21
  callback,
22
+ context,
22
23
  watchDotfiles = false,
23
24
  ignorePaths = [],
24
25
  watchPaths,
@@ -28,7 +29,7 @@ function setupWatcher({
28
29
  // const { watch = [], watchIgnore = [] } = context.options;
29
30
  // const resolvedWatchPaths = watch.map((pathName) => path.resolve(pathName));
30
31
 
31
- const batchChanges = new BatchChanges({ fn: callback, minDelay });
32
+ const batchChanges = new BatchChanges({ context, fn: callback, minDelay });
32
33
  const defaultIgnorePaths = watchDotfiles
33
34
  ? []
34
35
  : [
@@ -13,20 +13,20 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
17
  import path from 'path';
19
18
  import setupWatcher from '../utils/setupWatcher.mjs';
20
19
 
21
20
  function envWatcher(context) {
22
21
  const callback = async () => {
23
- console.warn('.env file changed.');
22
+ context.logger.warn('.env file changed.');
24
23
  context.readDotEnv();
25
24
  await context.lowdefyBuild();
26
25
  context.restartServer();
27
26
  };
28
27
  return setupWatcher({
29
28
  callback,
29
+ context,
30
30
  watchDotfiles: true,
31
31
  watchPaths: [path.join(context.directories.config, '.env')],
32
32
  });
@@ -13,7 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
17
  import getLowdefyVersion from '../utils/getLowdefyVersion.mjs';
19
18
  import setupWatcher from '../utils/setupWatcher.mjs';
@@ -27,7 +26,7 @@ function lowdefyBuildWatcher(context) {
27
26
  const lowdefyVersion = await getLowdefyVersion(context);
28
27
  if (lowdefyVersion !== context.version && lowdefyVersion !== 'local') {
29
28
  context.shutdownServer();
30
- console.warn('Lowdefy version changed. You should restart your development server.');
29
+ context.logger.warn('Lowdefy version changed. You should restart your development server.');
31
30
  process.exit();
32
31
  }
33
32
  }
@@ -37,6 +36,7 @@ function lowdefyBuildWatcher(context) {
37
36
  };
38
37
  return setupWatcher({
39
38
  callback,
39
+ context,
40
40
  ignorePaths: context.options.watchIgnore,
41
41
  watchPaths: [context.directories.config, ...context.options.watch],
42
42
  });
@@ -13,7 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable no-console */
17
16
 
18
17
  import crypto from 'crypto';
19
18
  import path from 'path';
@@ -23,9 +22,11 @@ import setupWatcher from '../utils/setupWatcher.mjs';
23
22
  const hashes = {};
24
23
 
25
24
  const watchedFiles = [
25
+ 'build/app.json',
26
26
  'build/auth.json',
27
27
  'build/config.json',
28
28
  'build/plugins/actions.js',
29
+ 'build/plugins/auth/adapters.js',
29
30
  'build/plugins/auth/callbacks.js',
30
31
  'build/plugins/auth/events.js',
31
32
  'build/plugins/auth/providers.js',
@@ -74,6 +75,7 @@ async function nextBuildWatcher(context) {
74
75
  );
75
76
 
76
77
  if (!build) {
78
+ context.logger.info({ print: 'succeed' }, 'Reloaded app.');
77
79
  return;
78
80
  }
79
81
 
@@ -87,13 +89,9 @@ async function nextBuildWatcher(context) {
87
89
 
88
90
  return setupWatcher({
89
91
  callback,
92
+ context,
90
93
  watchDotfiles: true,
91
- watchPaths: [
92
- path.join(context.directories.build, 'plugins'),
93
- path.join(context.directories.build, 'auth.json'),
94
- path.join(context.directories.build, 'config.json'),
95
- path.join(context.directories.server, 'package.json'),
96
- ],
94
+ watchPaths: watchedFiles.map((filePath) => path.join(context.directories.server, filePath)),
97
95
  });
98
96
  }
99
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "4.0.0-alpha.22",
3
+ "version": "4.0.0-alpha.25",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -39,34 +39,35 @@
39
39
  "next": "next"
40
40
  },
41
41
  "dependencies": {
42
- "@lowdefy/actions-core": "4.0.0-alpha.22",
43
- "@lowdefy/api": "4.0.0-alpha.22",
44
- "@lowdefy/blocks-antd": "4.0.0-alpha.22",
45
- "@lowdefy/blocks-basic": "4.0.0-alpha.22",
46
- "@lowdefy/blocks-color-selectors": "4.0.0-alpha.22",
47
- "@lowdefy/blocks-echarts": "4.0.0-alpha.22",
48
- "@lowdefy/blocks-loaders": "4.0.0-alpha.22",
49
- "@lowdefy/blocks-markdown": "4.0.0-alpha.22",
50
- "@lowdefy/build": "4.0.0-alpha.22",
51
- "@lowdefy/client": "4.0.0-alpha.22",
52
- "@lowdefy/connection-axios-http": "4.0.0-alpha.22",
53
- "@lowdefy/engine": "4.0.0-alpha.22",
54
- "@lowdefy/helpers": "4.0.0-alpha.22",
55
- "@lowdefy/layout": "4.0.0-alpha.22",
56
- "@lowdefy/node-utils": "4.0.0-alpha.22",
57
- "@lowdefy/operators-change-case": "4.0.0-alpha.22",
58
- "@lowdefy/operators-diff": "4.0.0-alpha.22",
59
- "@lowdefy/operators-js": "4.0.0-alpha.22",
60
- "@lowdefy/operators-mql": "4.0.0-alpha.22",
61
- "@lowdefy/operators-nunjucks": "4.0.0-alpha.22",
62
- "@lowdefy/operators-uuid": "4.0.0-alpha.22",
63
- "@lowdefy/operators-yaml": "4.0.0-alpha.22",
64
- "@lowdefy/plugin-next-auth": "4.0.0-alpha.22",
42
+ "@lowdefy/actions-core": "4.0.0-alpha.25",
43
+ "@lowdefy/api": "4.0.0-alpha.25",
44
+ "@lowdefy/blocks-antd": "4.0.0-alpha.25",
45
+ "@lowdefy/blocks-basic": "4.0.0-alpha.25",
46
+ "@lowdefy/blocks-color-selectors": "4.0.0-alpha.25",
47
+ "@lowdefy/blocks-echarts": "4.0.0-alpha.25",
48
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.25",
49
+ "@lowdefy/blocks-markdown": "4.0.0-alpha.25",
50
+ "@lowdefy/build": "4.0.0-alpha.25",
51
+ "@lowdefy/client": "4.0.0-alpha.25",
52
+ "@lowdefy/connection-axios-http": "4.0.0-alpha.25",
53
+ "@lowdefy/engine": "4.0.0-alpha.25",
54
+ "@lowdefy/helpers": "4.0.0-alpha.25",
55
+ "@lowdefy/layout": "4.0.0-alpha.25",
56
+ "@lowdefy/node-utils": "4.0.0-alpha.25",
57
+ "@lowdefy/operators-change-case": "4.0.0-alpha.25",
58
+ "@lowdefy/operators-diff": "4.0.0-alpha.25",
59
+ "@lowdefy/operators-js": "4.0.0-alpha.25",
60
+ "@lowdefy/operators-mql": "4.0.0-alpha.25",
61
+ "@lowdefy/operators-nunjucks": "4.0.0-alpha.25",
62
+ "@lowdefy/operators-uuid": "4.0.0-alpha.25",
63
+ "@lowdefy/operators-yaml": "4.0.0-alpha.25",
64
+ "@lowdefy/plugin-next-auth": "4.0.0-alpha.25",
65
65
  "chokidar": "3.5.3",
66
66
  "dotenv": "16.0.1",
67
67
  "next": "12.1.6",
68
- "next-auth": "4.9.0",
68
+ "next-auth": "4.10.3",
69
69
  "opener": "1.5.2",
70
+ "pino": "8.1.0",
70
71
  "process": "0.11.10",
71
72
  "react": "18.1.0",
72
73
  "react-dom": "18.1.0",
@@ -84,5 +85,5 @@
84
85
  "publishConfig": {
85
86
  "access": "public"
86
87
  },
87
- "gitHead": "66ce29562c016a8bcf0cbea4bbbbb71d364ae995"
88
+ "gitHead": "720e5090c9777fc2176517a53e88a3b81fc8c237"
88
89
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import React from 'react';
18
18
  import Document, { Html, Head, Main, NextScript } from 'next/document';
19
+ import appJson from '../build/app.json';
19
20
 
20
21
  class LowdefyDocument extends Document {
21
22
  render() {
@@ -25,10 +26,20 @@ class LowdefyDocument extends Document {
25
26
  <link rel="manifest" href="/manifest.webmanifest" />
26
27
  <link rel="icon" type="image/svg+xml" href="/icon.svg" />
27
28
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
29
+ <script
30
+ dangerouslySetInnerHTML={{
31
+ __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
32
+ }}
33
+ />
28
34
  </Head>
29
35
  <body>
30
36
  <Main />
31
37
  <NextScript />
38
+ <script
39
+ dangerouslySetInnerHTML={{
40
+ __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
41
+ }}
42
+ />
32
43
  </body>
33
44
  </Html>
34
45
  );
@@ -18,21 +18,19 @@ import NextAuth from 'next-auth';
18
18
  import { getNextAuthConfig } from '@lowdefy/api';
19
19
 
20
20
  import authJson from '../../../build/auth.json';
21
+ import adapters from '../../../build/plugins/auth/adapters.js';
21
22
  import callbacks from '../../../build/plugins/auth/callbacks.js';
22
23
  import events from '../../../build/plugins/auth/events.js';
23
24
  import providers from '../../../build/plugins/auth/providers.js';
24
25
 
25
- // TODO: make createApiContext synchronous
26
+ export const authOptions = getNextAuthConfig(
27
+ { logger: console }, // TODO: make createApiContext synchronous
28
+ { authJson, plugins: { adapters, callbacks, events, providers } }
29
+ );
30
+
26
31
  export default async function auth(req, res) {
27
32
  if (authJson.configured === true) {
28
- return await NextAuth(
29
- req,
30
- res,
31
- getNextAuthConfig(
32
- { logger: console },
33
- { authJson, plugins: { callbacks, events, providers } }
34
- )
35
- );
33
+ return await NextAuth(req, res, authOptions);
36
34
  }
37
35
 
38
36
  return res.status(404).json({
@@ -18,7 +18,7 @@ import { createApiContext, getPageConfig } from '@lowdefy/api';
18
18
  import getServerSession from '../../../lib/auth/getServerSession.js';
19
19
 
20
20
  export default async function handler(req, res) {
21
- const session = await getServerSession({ req });
21
+ const session = await getServerSession({ req, res });
22
22
  const apiContext = await createApiContext({
23
23
  buildDirectory: './build',
24
24
  logger: console,
@@ -26,7 +26,7 @@ export default async function handler(req, res) {
26
26
  if (req.method !== 'POST') {
27
27
  throw new Error('Only POST requests are supported.');
28
28
  }
29
- const session = await getServerSession({ req });
29
+ const session = await getServerSession({ req, res });
30
30
  const apiContext = await createApiContext({
31
31
  buildDirectory: './build',
32
32
  connections,
package/pages/api/root.js CHANGED
@@ -19,7 +19,7 @@ import { createApiContext, getRootConfig } from '@lowdefy/api';
19
19
  import getServerSession from '../../lib/auth/getServerSession.js';
20
20
 
21
21
  export default async function handler(req, res) {
22
- const session = await getServerSession({ req });
22
+ const session = await getServerSession({ req, res });
23
23
  const apiContext = await createApiContext({
24
24
  buildDirectory: './build',
25
25
  logger: console,
@@ -1,44 +0,0 @@
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 spawnProcess from '../utils/spawnProcess.mjs';
18
-
19
- function startServerProcess(context) {
20
- context.shutdownServer();
21
-
22
- const nextServer = spawnProcess({
23
- logger: console,
24
- command: 'node',
25
- args: [context.bin.next, 'start'],
26
- silent: false,
27
- processOptions: {
28
- env: {
29
- ...process.env,
30
- PORT: context.options.port,
31
- },
32
- },
33
- });
34
- // console.log(`Started server ${nextServer.pid}.`);
35
- // nextServer.on('exit', (code, signal) => {
36
- // console.log(`nextServer exit ${nextServer.pid}, signal: ${signal}, code: ${code}`);
37
- // });
38
- nextServer.on('error', (error) => {
39
- console.log(error);
40
- });
41
- context.nextServer = nextServer;
42
- }
43
-
44
- export default startServerProcess;
@@ -1,55 +0,0 @@
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 { 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;