Skip to content

Commit 6fceacd

Browse files
authored
Merge pull request #13 from hlambda/release/0.3.0
Release/0.3.0
2 parents 83379d9 + 9adbb3a commit 6fceacd

File tree

889 files changed

+128404
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

889 files changed

+128404
-733
lines changed

Diff for: .env.example

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ JSON_STDOUT="false"
1414
# Sets up logging level: critical, normal, verbose
1515
LOG_LEVELS="critical,normal,verbose"
1616

17+
# Constant reference in code: ENV_LOG_HISTORY_BUFFER_SIZE | Default value: 255
18+
# Sets up logging history buffer size. It is a max length of the history buffer, every record is the call of log function, that can contain multi-line text. (Default: 255)
19+
LOG_HISTORY_BUFFER_SIZE="255"
20+
21+
# Constant reference in code: ENV_EXPRESS_REQUEST_LOG_HISTORY_BUFFER_SIZE | Default value: 255
22+
# Sets up logging history buffer size. It is a max length of the history buffer, every record is the record of the request. (Default: 255)
23+
EXPRESS_REQUEST_LOG_HISTORY_BUFFER_SIZE="255"
24+
25+
# Constant reference in code: ENV_ENABLE_REQUEST_HISTORY | Default value: false
26+
# Enables request history, useful if you want to log the last n requests and be able to replay the request. (Default: false)
27+
ENABLE_REQUEST_HISTORY="false"
28+
1729
# Constant reference in code: ENV_SERVER_PORT | Default value: 1331
1830
# Server port on which express app will be hosted
1931
SERVER_PORT="1331"
@@ -34,6 +46,10 @@ PRIVATE_KEY_CONFIGURATION="__INSERT_YOUR_PRIVATE_KEY_CONFIGURATION__"
3446
# Server max allowed body size from client that express app will support. (Main usecase is Apple Subscription Notifications)
3547
SERVER_BODY_SIZE="2mb"
3648

49+
# Constant reference in code: ENV_SERVER_BODY_SIZE_ADMIN_CONSOLE | Default value: 50mb
50+
# Server max allowed body size from client that express app will support for admin console.
51+
SERVER_BODY_SIZE_ADMIN_CONSOLE="50mb"
52+
3753
# Constant reference in code: ENV_DISABLE_EXPRESS_BODY_PARSER | Default value: false
3854
# The Express body parser will be disabled for all routes except the ones required for Console.
3955
DISABLE_EXPRESS_BODY_PARSER="false"
@@ -82,6 +98,10 @@ HLAMBDA_CONSOLE_ASSETS_DIR="public"
8298
# Debounce ms time to wait before closing the server and reloading metadata.
8399
HLAMBDA_METADATA_RELOAD_DEBOUNCE_MS="1331"
84100

101+
# Constant reference in code: ENV_HLAMBDA_GRACEFUL_SHUTDOWN_DELAY_MS | Default value: 0
102+
# Graceful shutdown delay in ms, time to wait before closing the server (Used to give some time to the app to finish all processes after SIGINT).
103+
HLAMBDA_GRACEFUL_SHUTDOWN_DELAY_MS="0"
104+
85105
# Constant reference in code: ENV_HLAMBDA_LOADED_APPS_PREFIX | Default value:
86106
# Prefix used for all the loaded router apps.
87107
HLAMBDA_LOADED_APPS_PREFIX=""
@@ -94,6 +114,14 @@ HLAMBDA_ENABLE_PUBLIC_SWAGGER="false"
94114
# Flag to map swagger route, default `/docs`.
95115
HLAMBDA_PUBLIC_SWAGGER_ROUTE="/docs"
96116

117+
# Constant reference in code: ENV_HLAMBDA_SWAGGER_UI_TOKEN_EXPIRES_IN_SECONDS | Default value: 86400
118+
# Expires in value in seconds, time before JWT token expires and cookie is deleted on the client.
119+
HLAMBDA_SWAGGER_UI_TOKEN_EXPIRES_IN_SECONDS="86400"
120+
121+
# Constant reference in code: ENV_HLAMBDA_VSCODE_UI_TOKEN_EXPIRES_IN_SECONDS | Default value: 86400
122+
# Expires in value in seconds, time before JWT token expires and cookie is deleted on the client.
123+
HLAMBDA_VSCODE_UI_TOKEN_EXPIRES_IN_SECONDS="86400"
124+
97125
# Constant reference in code: ENV_HLAMBDA_CONFIGURATION_LOADER_PREFIX | Default value: hlambda-config.yaml
98126
# Sets the value for the name of the configuration file that will be loaded.
99127
HLAMBDA_CONFIGURATION_LOADER_PREFIX="hlambda-config.yaml"

Diff for: CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Release 0.3.0
2+
3+
- Added zero downtime reload.
4+
- Added fully featured vscode for editing metadata in Console UI
5+
- Added pre-installed Hlambda extension to custom vscode build.
6+
- Added pre-installed Hasura extension to custom vscode build.
7+
- Added pre-installed Color-Vision extension to custom vscode build.
8+
- Updated Console UI. Home page now shows both logs and Swagger UI.
9+
- Added support for saving request history, added replay option for the requests saved in request history.
10+
- Replaced terminal with vscode pseudo terminal.
11+
- Updated to new Hlambda logo.
12+
- Updated favicon.
13+
114
# Release 0.2.0
215

316
- Updated Console UI (Logs: Auto scroll snap, Metadata: Action history dates)

Diff for: Dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ RUN apk -U upgrade \
55
git \
66
openssh
77

8+
## Install Nginx (used for zero downtime)
9+
#RUN apk add nginx
10+
11+
#COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
12+
813
RUN mkdir -p /usr/src/app
914

1015
# Create app directory
@@ -31,7 +36,12 @@ RUN cd ./metadata && npm install --only=production
3136
# At the point of building image we also want to move metadata folder with npm modules to data/metadata-examples
3237
RUN cp -r ./metadata/* ./data/metadata-examples
3338

34-
CMD ["npm", "run", "start"]
39+
# Install PM2 globally
40+
RUN npm install pm2 -g
41+
42+
# CMD ["npm", "run", "start"]
43+
44+
CMD [ "pm2-runtime", "start", "ecosystem.config.cjs" ]
3545

3646
# This is not ready, there are known bugs with cluster mode (state management between nodes, like path in remote shell etc...)
3747
#CMD ["npm", "run", "cluster-runtime"]

Diff for: README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
## What is Hlambda (/hlæmdə/) [Hyper Lambda]
99

10-
Hlambda is ECMAScript meta API service. That means that it offers simple ways to deploy ECMAScript code to local or remote servers.
10+
Hlambda is ECMAScript meta API service. It offers simple ways to deploy ECMAScript code to local or remote servers.
1111

1212
<a href="https://hub.docker.com/r/hlambda/hlambda-core" title="Docker Image">
1313

1414
<picture>
15-
<source media="(prefers-color-scheme: dark)" srcset="https://www.hlambda.io/assets/hlambda-logo-light.png">
16-
<source media="(prefers-color-scheme: light)" srcset="https://www.hlambda.io/assets/hlambda-logo-dark.png">
17-
<img alt="Hlambda Banner" src="https://www.hlambda.io/assets/hlambda-logo-dark.png">
15+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/hlambda/hlambda-core/master/public/static/images/hlambda-logo-banner-light-blue.png">
16+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/hlambda/hlambda-core/master/public/static/images/hlambda-logo-banner-blue.png">
17+
<img alt="Hlambda Banner" src="https://raw.githubusercontent.com/hlambda/hlambda-core/master/public/static/images/hlambda-logo-banner-blue.png">
1818
</picture>
1919

2020
</a>
2121

22-
It is the implementation of the idea to load your ECMAScript code as configuration (metadata). With Hlambda you can easily create a microservice that can load arbitrary code configuration.
22+
It is the implementation of the idea to load your ECMAScript code as configuration (metadata). With Hlambda you can easily create a microservice that can load arbitrary code configurations.
2323

2424
The main use case was to implement a stateless REST microservice that will run Hasura custom actions in a separate container, containing any custom business logic.
2525

Diff for: docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Hlambda is easy to manage, meta ECMAScript API server, with console UI and CLI t
1515

1616
Your ECMAScript metadata payload is the configuration of the (Hyper Lambda) Hlambda Server.
1717

18-
![Hlambda Banner](https://www.hlambda.io/assets/hlambda-logo-dark.png)
18+
![Hlambda Banner](https://raw.githubusercontent.com/hlambda/hlambda-core/master/public/static/images/hlambda-logo-banner-blue.png)
1919

2020
# How to use this image
2121

Diff for: ecosystem.config.cjs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: 'Backend Microservice',
5+
script: 'src/index.js',
6+
// script: 'npm', // Do not use this, express port binding will be problematic with npm start
7+
// args: 'run start', // Look abowe
8+
9+
exec_mode: 'cluster',
10+
11+
instances: 1, // Important!!! (Hlambda is stateless but shell, logs and other routes are not shared)
12+
autorestart: true, // Set autorestart if there is unexpected error.
13+
max_memory_restart: '2G',
14+
15+
// Watch is problematic, it will issue pm2 restart instead of pm2 reload
16+
// watch: false,
17+
// watch: 'watcher_trigger/', // This only works if dot files / folders are not used, due to chokidar and pm2 :(
18+
19+
// Delay between restart
20+
// watch_delay: 1000,
21+
listen_timeout: 15000,
22+
wait_ready: true,
23+
kill_timeout: 60000, // Amount of time waiting after SIGINT to execute SIGKILL
24+
25+
out_file: '/dev/null',
26+
error_file: '/dev/null',
27+
28+
vizion: false,
29+
pmx: false,
30+
31+
// output: '/dev/null', // This will disable stdout logs even for windows :)
32+
// error: '/dev/null', // This will disable stderr logs even for windows :)
33+
// log: true, // This will enable combined stdout and stderr logs, without giving a path
34+
// log_type: 'json', // This will transform output to JSON
35+
// merge_logs: true, // This will combine stdout and stderr logs, without giving a path
36+
},
37+
],
38+
};

Diff for: ecosystem.config.js

-29
This file was deleted.

Diff for: metadata/apps/auth/routes/router.auth.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
import express from 'express';
22
import asyncHandler from 'express-async-handler';
3-
43
import { DateTime } from 'luxon';
5-
64
import hasuraRequestLogger from './../hasura-request-logger.js';
7-
85
import errors from './../errors.demo.js';
96

10-
// Create express router
117
const router = express.Router();
128

139
router.use('/hook/auth*', hasuraRequestLogger);
1410

1511
router.get(
1612
'/hook/auth',
17-
asyncHandler((req, res) => {
18-
res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
19-
})
20-
);
21-
22-
router.get(
23-
'/hook/auth-error',
24-
asyncHandler((req, res) => {
25-
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
26-
throw new Error(errors.SOMETHING_WENT_TERRIBLY_WRONG);
27-
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
13+
asyncHandler(async (req, res) => {
14+
res.send(`Demo auth hook works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
2815
})
2916
);
3017

Diff for: metadata/apps/auth/routes/router.cookies.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import express from 'express';
22
import asyncHandler from 'express-async-handler';
3-
43
import cookieParser from 'cookie-parser';
5-
64
import errors from './../errors.demo.js';
75

86
// Create express router
@@ -12,15 +10,15 @@ const router = express.Router();
1210

1311
router.get(
1412
'/cookie/set',
15-
asyncHandler((req, res) => {
13+
asyncHandler(async (req, res) => {
1614
res.cookie('demo-jwt-token', 'token ey...', { maxAge: 10800 });
1715
res.send(`Demo token set!`);
1816
})
1917
);
2018

2119
router.get(
2220
'/cookie/get',
23-
asyncHandler((req, res) => {
21+
asyncHandler(async (req, res) => {
2422
console.log('Cookies: ', req.cookies);
2523
res.send(JSON.stringify(req.cookies, null, 2));
2624
})

Diff for: metadata/apps/bad-app/router.async-issue.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
// Uncomment this file to test how Hlambda handles bad code with errors.
3+
4+
import express from 'express';
5+
import asyncHandler from 'express-async-handler';
6+
7+
// Create express router
8+
const router = express.Router();
9+
10+
// This app is intentionally wrong, fix it your self to see that even broken scripts won't kill hlambda container
11+
12+
router.get(
13+
'/await-but-not-async',
14+
asyncHandler(
15+
// async
16+
(req, res) => {
17+
await (async () => {})()
18+
res.send(`Be careful that your resolver really is async when you use await. There will be no stacktrace`);
19+
})
20+
);
21+
22+
export default router;
23+
24+
*/

Diff for: metadata/apps/bad-app/router.auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ zzzzz;
1616
1717
router.get(
1818
'/share-dependency',
19-
asyncHandler((req, res) => {
19+
asyncHandler(async (req, res) => {
2020
res.send(`Prototype login works: ${DateTime.now()}`);
2121
})
2222
);

Diff for: metadata/apps/example-demo-app/hlambda-config.yaml

+31-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
# Defines if the app is enabled or not, disabled apps are skipped from importing
2-
enabled: true
3-
# # Defines if we want to use namespace or not
4-
# use_namespace: true # NOT IN USE!
5-
# # Define the namespace name
6-
# namespace_name: 'demo_app' # NOT IN USE!
7-
# Custom environment variables override for our app
81
env:
9-
HASURA_GRAPHQL_API_ENDPOINT: "http://graphql-engine:8099/v1/graphql"
10-
HASURA_GRAPHQL_ADMIN_SECRET: "hlambda-test"
11-
HLAMBDA_DISABLE_CONSOLE: "false"
12-
2+
HASURA_GRAPHQL_API_ENDPOINT: 'http://graphql-engine:8099/v1/graphql'
3+
HASURA_GRAPHQL_ADMIN_SECRET: 'hlambda-test'
4+
HLAMBDA_DISABLE_CONSOLE: 'false'
5+
ENABLE_REQUEST_HISTORY: 'true'
6+
137
#HLAMBDA_ENABLE_ENVIRONMENT_BANNER: "true"
148
#HLAMBDA_ENVIRONMENT_BANNER_NAME: "Local Hlambda Demo Development"
159
#HLAMBDA_ENVIRONMENT_BANNER_MESSAGE: "Hello Hlambda Env Banner!"
1610
#HLAMBDA_ENABLE_ENVIRONMENT_BANNER_COLOR: "#eeFF22"
1711

1812
#JSON_STDOUT: true
1913

14+
# Custom environment variables override for our app
2015
envForce:
21-
HASURA_GRAPHQL_API_ENDPOINT: "http://graphql-engine:8099/v1/graphql"
22-
HASURA_GRAPHQL_ADMIN_SECRET: "real-password"
23-
SPECIAL_PASSWORD: "value-from-env"
24-
HLAMBDA_DISABLE_CONSOLE: "false"
16+
HASURA_GRAPHQL_API_ENDPOINT: 'http://graphql-engine:8099/v1/graphql'
17+
HASURA_GRAPHQL_ADMIN_SECRET: 'real-password'
18+
SPECIAL_PASSWORD: 'value-from-env'
19+
HLAMBDA_DISABLE_CONSOLE: 'false'
20+
21+
# Consider that cwd for the script is ./metadata/ , also we suggest that you do not deploy ts as metadata, only js and do transpilation before metadata apply.
22+
# But if you want you can slow down the reload time and await for scripts to run after every reload.
23+
#postReloadScripts:
24+
# - npm install --only=production
25+
# - npx tsc --module ES2020 ./apps/example-demo-app/router.demo-ts.ts
26+
27+
# If used routers and entrypoints are skipped from importing
28+
#ignoreRouters: './*' # use `true` for all
29+
#ignoreEntrypoints: './*' # use `true` for all
30+
31+
# Defines if the app is enabled or not, disabled apps are not applied (configuration is ignored)
32+
#enabled: false # default true
33+
34+
# --- Proposals ---
35+
36+
# # Defines if we want to use namespace or not
37+
# use_namespace: true # NOT IN USE!
38+
39+
# # Define the namespace name
40+
# namespace_name: 'demo_app' # NOT IN USE!

0 commit comments

Comments
 (0)