Skip to content

Commit 72d0e8f

Browse files
authored
Release/0.1.0 (#11)
* docs: 📝 Update README.md Add shields, update information, add logo for both light and dark theme. * fix: 🐛 Use picture tag https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to * fix: 📝 Add new line * feat: ✨ Improve order for serving static files, implement remote version check, fix env banner API response Improve serving static files by updating the order of the hlapp's loading pattern, this enables serving static files that have naming collision with hlambda's example: favicon.ico, add remote version check via github API, fix env banner boolean flags, update example metadata * feat: ✨ Update UI Update image to contain new UI files * fix: 🎨 Update example metadata Update metadata example to match yaml syntax * fix: 🐛 Remove duplicate shields in README.md * fix: 🐛 Add .env to .dockerignore, update defaults in constants Add .env to .dockerignore, update defaults in constants.js, update new version to beta.4, add output for environment, added file upload to editor * feat: 🚀 Add new UI to the core * feat: 🚀 Add support for socket.io, update metadata example, add metadata history Add support for socket.io, update metadata example including socket.io example, add metadata history and timestamps. * feat: 🚀 Update UI to v0.0.7 Update Console UI to v0.0.7 * fix: 🐛 Fixes Return valid content for metadata-history * feat: 🚀 Update UI, update CHANGELOG.md * feat: 🎨 Added support for JSON output, prepare code for next minor version release Added support for JSON output to stdout, added new env variable JSON_STDOUT default:false, bugfixes * feat: 🎨 Update Core Console UI * fix: 🐛 Fix metadata reset Fix metadata reset, fix typo * fix: 🐛 Fix logged text, fix swagger's custom js * fix: 🐛 Fix metadata example copy location
1 parent b51d749 commit 72d0e8f

Some content is hidden

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

44 files changed

+633
-96
lines changed

.dockerignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# Note .dockerignore syntax is a bit different than .gitignore
2+
13
.git/
24
.github/
35
node_modules/
46

5-
watcher_trigger/
7+
watcher_trigger/*
68
!watcher_trigger/.gitkeep
79

8-
data/
9-
!data/.gitkeep
10+
data/metadata-history/*
11+
!data/metadata-history/.gitkeep
1012

1113
metadata_tmp/
1214

.env.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
NODE_ENV="development"
44

55
# Constant reference in code: ENV_DISABLE_COLORS_IN_STDOUT | Default value: false
6-
# Set to true if you want to disable colorful output to stdout, it helps if you use AWS CloudWatch
6+
# Set to true if you want to disable colorful output to stdout, it helps if you use AWS CloudWatch.
77
DISABLE_COLORS_IN_STDOUT="false"
88

9+
# Constant reference in code: ENV_JSON_STDOUT | Default value: false
10+
# Set to true if you want to get JSON output to stdout, it helps if you use AWS CloudWatch.
11+
JSON_STDOUT="false"
12+
913
# Constant reference in code: ENV_LOG_LEVELS | Default value: critical,normal,verbose
1014
# Sets up logging level: critical, normal, verbose
1115
LOG_LEVELS="critical,normal,verbose"

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
node_modules/
2-
metadata/
32

4-
watcher_trigger/
3+
watcher_trigger/*
54
!watcher_trigger/.gitkeep
65

7-
data/
8-
!data/.gitkeep
6+
data/metadata-history/*
7+
!data/metadata-history/.gitkeep
98

109
# development
1110
metadata_tmp/

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# (Future) Release 0.0.10
1+
# Release 0.1.0
22

3-
- undefined
3+
- Added support for JSON output to stdout, new env variable `JSON_STDOUT` default:false
4+
- Restructured metadata example location, moved examples to `./data/metadata-examples`
5+
- Added ability to reset metadata, which will reset metadata to initial image example metadata.
6+
- Updated UI
7+
- Bugfixes
48

59
# Release 0.0.9
610

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ COPY . .
2828
# Install node_modules in metadata folder on build
2929
RUN cd ./metadata && npm install --only=production
3030

31+
# At the point of building image we also want to move metadata folder with npm modules to data/metadata-examples
32+
RUN cp -r ./metadata/* ./data/metadata-examples
33+
3134
CMD ["npm", "run", "start"]
3235

3336
# This is not ready, there are known bugs with cluster mode (state management between nodes, like path in remote shell etc...)

data/.gitkeep

Whitespace-only changes.

data/metadata-examples/.gitkeep

Whitespace-only changes.

data/metadata-history/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createErrorDescriptor } from 'hlambda';
2+
3+
// --- START SAFE TO EDIT ---
4+
5+
export const errorsGroupName = 'demo-hlambda-app';
6+
7+
export const errors = {
8+
FUNCTIONALITY_NOT_IMPLEMENTED: {
9+
message:
10+
'Specific functionality is still in development. (It should be available soon, thank you for understanding.)',
11+
},
12+
SOMETHING_WENT_TERRIBLY_WRONG: {
13+
message: 'Description of an error message...',
14+
},
15+
};
16+
17+
// --- STOP SAFE TO EDIT ---
18+
19+
export const ed = createErrorDescriptor(errors, errorsGroupName);
20+
21+
export default errors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'colors';
2+
3+
const hasuraRequestLogger = (req, res, next) => {
4+
console.log(`[${req.originalUrl}] Request hit!`);
5+
// --------------------------------------------------------------------------------
6+
// Get variables
7+
console.log('This is what we received from Hasura when calling the hook');
8+
console.log(req.body);
9+
console.log(Array(80 + 1).join('-'));
10+
// --------------------------------------------------------------------------------
11+
next();
12+
};
13+
14+
export default hasuraRequestLogger;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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
8+
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+
13+
#HLAMBDA_ENABLE_ENVIRONMENT_BANNER: "true"
14+
#HLAMBDA_ENVIRONMENT_BANNER_NAME: "Local Hlambda Demo Development"
15+
#HLAMBDA_ENVIRONMENT_BANNER_MESSAGE: "Hello Hlambda Env Banner!"
16+
#HLAMBDA_ENABLE_ENVIRONMENT_BANNER_COLOR: "#eeFF22"
17+
18+
#JSON_STDOUT: true
19+
20+
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"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import express from 'express';
2+
import asyncHandler from 'express-async-handler';
3+
4+
import { DateTime } from 'luxon';
5+
6+
import hasuraRequestLogger from './hasura-request-logger.js';
7+
8+
import errors from './errors.demo.js';
9+
10+
import requestTimeLogger from '../../../src/utils/requestTimer.js';
11+
12+
// Create express router
13+
const router = express.Router();
14+
15+
router.use('/demo*', hasuraRequestLogger);
16+
router.use('/demo*', requestTimeLogger);
17+
18+
router.get(
19+
'/demo',
20+
asyncHandler((req, res) => {
21+
res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
22+
})
23+
);
24+
25+
router.get(
26+
'/demo-error',
27+
asyncHandler((req, res) => {
28+
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
29+
throw new Error(errors.SOMETHING_WENT_TERRIBLY_WRONG);
30+
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
31+
})
32+
);
33+
34+
export default router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createErrorDescriptor } from 'hlambda';
2+
3+
// --- START SAFE TO EDIT ---
4+
5+
export const errorsGroupName = 'example-hasura-app';
6+
7+
export const errors = {
8+
FUNCTIONALITY_NOT_IMPLEMENTED: {
9+
message:
10+
'Specific functionality is still in development. (It should be available soon, thank you for understanding.)',
11+
},
12+
SOMETHING_WENT_TERRIBLY_WRONG: {
13+
message: 'Description of an error message...',
14+
},
15+
};
16+
17+
// --- STOP SAFE TO EDIT ---
18+
19+
export const ed = createErrorDescriptor(errors, errorsGroupName);
20+
21+
export default errors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// import 'colors'; // This is known issue with this package...
2+
3+
const hasuraRequestLogger = (req, res, next) => {
4+
console.log(`[${req.originalUrl}] Request hit!`);
5+
// --------------------------------------------------------------------------------
6+
// Get variables
7+
console.log('This is what we received from Hasura when calling the hook');
8+
console.log(req.body);
9+
console.log(Array(80 + 1).join('-'));
10+
// --------------------------------------------------------------------------------
11+
next();
12+
};
13+
14+
export default hasuraRequestLogger;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
env:
2+
APP_VERSION: "v1.0.0"
3+
envForce:
4+
APP_VERSION: "v1.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import express from 'express';
2+
import asyncHandler from 'express-async-handler';
3+
4+
// Import our custom request logger
5+
import hasuraRequestLogger from './hasura-request-logger.js';
6+
7+
// Import our errors definition
8+
import errors from './errors.demo.js';
9+
10+
// Create express router
11+
const router = express.Router();
12+
13+
router.use('/hasura-*', hasuraRequestLogger);
14+
15+
router.post(
16+
'/hasura-version',
17+
asyncHandler((req, res) => {
18+
console.log(`${process.env.APP_VERSION}`);
19+
throw new Error(errors.SOMETHING_WENT_TERRIBLY_WRONG);
20+
// res.json({
21+
// version: `${process.env.APP_VERSION}`,
22+
// });
23+
})
24+
);
25+
26+
export default router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createErrorDescriptor } from 'hlambda';
2+
3+
// --- START SAFE TO EDIT ---
4+
5+
export const errorsGroupName = 'socket-io';
6+
7+
export const errors = {
8+
SOCKET_SERVER_NOT_RUNNING: {
9+
message: 'Socket server is not available.',
10+
},
11+
};
12+
13+
// --- STOP SAFE TO EDIT ---
14+
15+
export const ed = createErrorDescriptor(errors, errorsGroupName);
16+
17+
export default errors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Socket.IO chat</title>
5+
<style>
6+
html {
7+
color-scheme: dark !important;
8+
}
9+
html, body {
10+
background-color:#181a1b;
11+
}
12+
body { margin: 0; padding-bottom: 3rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
13+
body {
14+
border-color: #736b5e;
15+
color: #e8e6e3;
16+
}
17+
18+
#form { background: rgba(0, 0, 0, 0.15); padding: 0.25rem; position: fixed; bottom: 0; left: 0; right: 0; display: flex; height: 3rem; box-sizing: border-box; backdrop-filter: blur(10px); }
19+
#input { border: none; padding: 0 1rem; flex-grow: 1; border-radius: 2rem; margin: 0.25rem; }
20+
#input:focus { outline: none; }
21+
#form > button { background: #333; border: none; padding: 0 1rem; margin: 0.25rem; border-radius: 3px; outline: none; color: #fff; }
22+
23+
24+
#messages { list-style-type: none; margin: 0; padding: 0; }
25+
#messages > li { padding: 0.5rem 1rem; }
26+
#messages > li:nth-child(odd) { background: #212425; }
27+
</style>
28+
</head>
29+
<body>
30+
<ul id="messages"></ul>
31+
<form id="form" action="">
32+
<input id="input" autocomplete="off" /><button>Send</button>
33+
</form>
34+
<!-- <script src="https://cdn.socket.io/4.5.0/socket.io.min.js" integrity="sha384-7EyYLQZgWBi67fBtVxw60/OWl1kjsfrPFcaU0pp0nAh+i8FD068QogUvg85Ewy1k" crossorigin="anonymous"></script> -->
35+
<script src="/socket.io/socket.io.js"></script>
36+
37+
<script>
38+
var socket = io();
39+
40+
var messages = document.getElementById('messages');
41+
var form = document.getElementById('form');
42+
var input = document.getElementById('input');
43+
44+
form.addEventListener('submit', function(e) {
45+
e.preventDefault();
46+
if (input.value) {
47+
socket.emit('chat message', input.value);
48+
input.value = '';
49+
}
50+
});
51+
52+
socket.on('chat message', function(msg) {
53+
var item = document.createElement('li');
54+
item.textContent = msg;
55+
messages.appendChild(item);
56+
window.scrollTo(0, document.body.scrollHeight);
57+
});
58+
</script>
59+
</body>
60+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable no-underscore-dangle */
2+
import { fileURLToPath } from 'url';
3+
import path, { dirname } from 'path';
4+
5+
import express from 'express';
6+
import asyncHandler from 'express-async-handler';
7+
import { Server } from 'socket.io';
8+
9+
import { executeWithAdminRights, getEnvValue, isEnvTrue } from 'hlambda';
10+
11+
// // Define constants & errors
12+
// import constants from "./../../constants/constants.index.js";
13+
import errors from './errors.socket-io.js';
14+
15+
const __filename = fileURLToPath(import.meta.url);
16+
const __dirname = dirname(__filename);
17+
18+
// Pull from global scope hlambdaEventEmitter
19+
const { hlambdaEventEmitter } = global;
20+
// --------------------------------------------------------------------------------
21+
// Why do we do this?
22+
// Hlambda emitts event 'server-ready' when the server starts to listen. In that event we have reference to server instance.
23+
// Socket.io needs that server instance reference to work. This is not necessary if you want to run another server on different port.
24+
let io;
25+
const attachSocketIoServer = async (server) => {
26+
// const server = await global.HLAMBDA_SERVER_INSTANCE;
27+
// const io = new Server(server, {});
28+
io = new Server(server, {}); // We want to use io from router.
29+
30+
io.on('connection', (socket) => {
31+
console.log('Socket connected!');
32+
33+
socket.on('chat message', (msg) => {
34+
io.emit('chat message', msg);
35+
});
36+
37+
socket.on('disconnect', () => {
38+
console.log('Socket disconnected!');
39+
});
40+
});
41+
};
42+
43+
// Listen for event.
44+
hlambdaEventEmitter.on('server-ready', (server) => {
45+
console.log(`[hlambdaEventEmitter] 'server-ready' event occurred!`.green);
46+
attachSocketIoServer(server);
47+
});
48+
// --------------------------------------------------------------------------------
49+
50+
// Create express router
51+
const router = express.Router();
52+
53+
// Example of serving static files on route /io
54+
router.use('/io', express.static(path.resolve(__dirname, './public')));
55+
56+
router.get(
57+
'/io/msg',
58+
asyncHandler((req, res) => {
59+
if (typeof io === 'undefined') {
60+
throw new Error(errors.SOCKET_SERVER_NOT_RUNNING);
61+
}
62+
63+
io.emit('chat message', 'Server message!');
64+
65+
res.json({
66+
done: true,
67+
});
68+
})
69+
);
70+
71+
export default router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Uncomment this for static serving.
2+
3+
#envForce:
4+
# HLAMBDA_DISABLE_INITIAL_ROUTE_REDIRECT: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x

0 commit comments

Comments
 (0)