feat: use lowdefy server in docker and lambda servers

This commit is contained in:
SamTolmay 2021-06-03 13:27:44 +02:00
parent dc4848a28f
commit 4854f74733
6 changed files with 18 additions and 86 deletions

2
.pnp.cjs generated
View File

@ -5095,6 +5095,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@lowdefy/block-tools", "workspace:packages/blockTools"],
["@lowdefy/graphql", "workspace:packages/graphql"],
["@lowdefy/node-utils", "workspace:packages/nodeUtils"],
["@lowdefy/server", "workspace:packages/server"],
["apollo-server-express", "virtual:dddca670fd0b7758fb2e1b1a3e18ac7ebd1ecd06ecdd7acec2b78bccf1d35802cb22904bfbb233b16515a81f5cb819421786d20887823d98022b367036c1ad51#npm:2.25.0"],
["babel-jest", "virtual:caddf51df4928b33a437ca87b8f5ddfb6205ebd6d8231f74d4ee7223f3866e6f815b221aa1e2bd33e98915f701e95bae72a93d2288b49a34a6246bdbc2a4a132#npm:26.6.3"],
["babel-loader", "virtual:45acfdba827b9fa2f59b603e806acbd96025d9a5a49d046592d9fa5046fb2bd7b340529d8bcc1cc579f8def2790be10259cc83aeba4cae3a015bb3336c52b7fd#npm:8.2.2"],
@ -5128,6 +5129,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@lowdefy/block-tools", "workspace:packages/blockTools"],
["@lowdefy/graphql", "workspace:packages/graphql"],
["@lowdefy/node-utils", "workspace:packages/nodeUtils"],
["@lowdefy/server", "workspace:packages/server"],
["apollo-server-express", "virtual:dddca670fd0b7758fb2e1b1a3e18ac7ebd1ecd06ecdd7acec2b78bccf1d35802cb22904bfbb233b16515a81f5cb819421786d20887823d98022b367036c1ad51#npm:2.25.0"],
["babel-jest", "virtual:caddf51df4928b33a437ca87b8f5ddfb6205ebd6d8231f74d4ee7223f3866e6f815b221aa1e2bd33e98915f701e95bae72a93d2288b49a34a6246bdbc2a4a132#npm:26.6.3"],
["babel-loader", "virtual:9d140c8c7e6cf46aed8abf40a0f1bf143eebb4006f69fe73c8eb6fee0d95a298d9eac70e1d5fef379a61bbc3388e8980bc436bdda5d2d7973ef5d5fff7b04ea0#npm:8.2.2"],

View File

@ -42,6 +42,7 @@
"dependencies": {
"@lowdefy/graphql": "3.16.5",
"@lowdefy/node-utils": "3.16.5",
"@lowdefy/server": "3.16.5",
"apollo-server-express": "2.25.0",
"express": "4.17.1",
"graphql": "15.5.0"

View File

@ -14,54 +14,17 @@
limitations under the License.
*/
import path from 'path';
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import { typeDefs, resolvers, createContext } from '@lowdefy/graphql';
import { createGetSecretsFromEnv, readFile } from '@lowdefy/node-utils';
import getServer from '@lowdefy/server';
import { createGetSecretsFromEnv } from '@lowdefy/node-utils';
const configurationBasePath = process.env.LOWDEFY_SERVER_CONFIGURATION_PATH || './build';
const port = parseInt(process.env.LOWDEFY_SERVER_PORT) || 443;
const config = {
CONFIGURATION_BASE_PATH: path.resolve(configurationBasePath),
const server = getServer({
configurationBasePath,
development: false,
getSecrets: createGetSecretsFromEnv(),
logger: console,
};
const context = createContext(config);
const server = new ApolloServer({
typeDefs,
resolvers,
context,
});
let indexHtml = null;
const serveIndex = async (req, res) => {
if (!indexHtml) {
indexHtml = await readFile(path.resolve(process.cwd(), 'dist/shell/index.html'));
let appConfig = await readFile(path.resolve(config.CONFIGURATION_BASE_PATH, 'app.json'));
appConfig = JSON.parse(appConfig);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_HEAD_HTML__ -->', appConfig.html.appendHead);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_BODY_HTML__ -->', appConfig.html.appendBody);
}
res.send(indexHtml);
};
const app = express();
server.applyMiddleware({ app, path: '/api/graphql' });
// serve index.html with appended html
// else static server serves without appended html
app.get('/', serveIndex);
// Serve Webpack shell files from './shell/dist'
app.use(express.static('dist/shell'));
// Redirect all 404 to index.html with status 200
// This should always be the last route
app.use(serveIndex);
app.listen({ port }, () => console.log(`Server started at port ${port}`));
server.listen({ port }, () => console.log(`Server started at port ${port}`));

View File

@ -42,6 +42,7 @@
"dependencies": {
"@lowdefy/graphql": "3.16.5",
"@lowdefy/node-utils": "3.16.5",
"@lowdefy/server": "3.16.5",
"apollo-server-express": "2.25.0",
"express": "4.17.1",
"graphql": "15.5.0",

View File

@ -14,56 +14,19 @@
limitations under the License.
*/
import path from 'path';
import serverless from 'serverless-http';
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import { typeDefs, resolvers, createContext } from '@lowdefy/graphql';
import { createGetSecretsFromEnv, readFile } from '@lowdefy/node-utils';
import getServer from '@lowdefy/server';
import { createGetSecretsFromEnv } from '@lowdefy/node-utils';
const configurationBasePath = process.env.LOWDEFY_SERVER_CONFIGURATION_PATH || './build';
const config = {
CONFIGURATION_BASE_PATH: path.resolve(configurationBasePath),
const server = getServer({
configurationBasePath,
development: false,
getSecrets: createGetSecretsFromEnv(),
logger: console,
};
const context = createContext(config);
const server = new ApolloServer({
typeDefs,
resolvers,
context,
});
let indexHtml = null;
const serveIndex = async (req, res) => {
if (!indexHtml) {
indexHtml = await readFile(path.resolve(process.cwd(), 'dist/shell/index.html'));
let appConfig = await readFile(path.resolve(config.CONFIGURATION_BASE_PATH, 'app.json'));
appConfig = JSON.parse(appConfig);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_HEAD_HTML__ -->', appConfig.html.appendHead);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_BODY_HTML__ -->', appConfig.html.appendBody);
}
res.send(indexHtml);
};
const app = express();
server.applyMiddleware({ app, path: '/api/graphql' });
// serve index.html with appended html
// else static server serves without appended html
app.get('/', serveIndex);
// Serve Webpack shell files from './shell/dist'
app.use(express.static('dist/shell'));
// Redirect all 404 to index.html with status 200
// This should always be the last route
app.use(serveIndex);
export const handler = serverless(app, {
export const handler = serverless(server, {
binary: ['image/png'],
});

View File

@ -3503,6 +3503,7 @@ __metadata:
"@lowdefy/block-tools": 3.16.5
"@lowdefy/graphql": 3.16.5
"@lowdefy/node-utils": 3.16.5
"@lowdefy/server": 3.16.5
apollo-server-express: 2.25.0
babel-jest: 26.6.3
babel-loader: 8.2.2
@ -3534,6 +3535,7 @@ __metadata:
"@lowdefy/block-tools": 3.16.5
"@lowdefy/graphql": 3.16.5
"@lowdefy/node-utils": 3.16.5
"@lowdefy/server": 3.16.5
apollo-server-express: 2.25.0
babel-jest: 26.6.3
babel-loader: 8.2.2