Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9b7de1d
docs: :memo: Update README.md
gnekich Jul 2, 2022
20081f8
fix: :bug: Use picture tag
gnekich Jul 2, 2022
ed2524d
fix: :memo: Add new line
gnekich Jul 2, 2022
198d994
feat: :sparkles: Improve order for serving static files, implement re…
gnekich Jul 20, 2022
454f41c
feat: :sparkles: Update UI
gnekich Jul 20, 2022
59ee053
fix: :art: Update example metadata
gnekich Jul 20, 2022
cee617d
fix: :bug: Remove duplicate shields in README.md
gnekich Jul 20, 2022
0d3df7a
Merge branch 'master' into release/0.0.8
gnekich Jul 20, 2022
93741aa
fix: :bug: Add .env to .dockerignore, update defaults in constants
gnekich Jul 27, 2022
7673a4e
feat: :rocket: Add new UI to the core
gnekich Jul 27, 2022
290e231
feat: :rocket: Add support for socket.io, update metadata example, ad…
gnekich Jul 29, 2022
831b396
feat: :rocket: Update UI to v0.0.7
gnekich Jul 29, 2022
7d91454
fix: :bug: Fixes
gnekich Jul 29, 2022
6b3d363
feat: :rocket: Update UI, update CHANGELOG.md
gnekich Jul 29, 2022
d507882
Merge branch 'master' into release/0.0.9
gnekich Jul 29, 2022
e9e2999
feat: :art: Added support for JSON output, prepare code for next mino…
gnekich Jul 30, 2022
24b109e
feat: :art: Update Core Console UI
gnekich Jul 30, 2022
a53b6e9
fix: :bug: Fix metadata reset
gnekich Jul 30, 2022
cc5464d
fix: :bug: Fix logged text, fix swagger's custom js
gnekich Jul 31, 2022
3db27c6
Merge branch 'master' into release/0.1.0
gnekich Jul 31, 2022
9ccb82b
fix: :bug: Fix metadata example copy location
gnekich Jul 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Note .dockerignore syntax is a bit different than .gitignore

.git/
.github/
node_modules/

watcher_trigger/
watcher_trigger/*
!watcher_trigger/.gitkeep

data/
!data/.gitkeep
data/metadata-history/*
!data/metadata-history/.gitkeep

metadata_tmp/

Expand Down
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
NODE_ENV="development"

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

# Constant reference in code: ENV_JSON_STDOUT | Default value: false
# Set to true if you want to get JSON output to stdout, it helps if you use AWS CloudWatch.
JSON_STDOUT="false"

# Constant reference in code: ENV_LOG_LEVELS | Default value: critical,normal,verbose
# Sets up logging level: critical, normal, verbose
LOG_LEVELS="critical,normal,verbose"
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
node_modules/
metadata/

watcher_trigger/
watcher_trigger/*
!watcher_trigger/.gitkeep

data/
!data/.gitkeep
data/metadata-history/*
!data/metadata-history/.gitkeep

# development
metadata_tmp/
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# (Future) Release 0.0.10
# Release 0.1.0

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

# Release 0.0.9

Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ COPY . .
# Install node_modules in metadata folder on build
RUN cd ./metadata && npm install --only=production

# At the point of building image we also want to move metadata folder with npm modules to data/metadata-examples
RUN cp -r ./metadata/* ./data/metadata-examples

CMD ["npm", "run", "start"]

# This is not ready, there are known bugs with cluster mode (state management between nodes, like path in remote shell etc...)
Expand Down
Empty file added data/.gitkeep
Empty file.
Empty file added data/metadata-examples/.gitkeep
Empty file.
Empty file added data/metadata-history/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions metadata/apps/example-demo-app/errors.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createErrorDescriptor } from 'hlambda';

// --- START SAFE TO EDIT ---

export const errorsGroupName = 'demo-hlambda-app';

export const errors = {
FUNCTIONALITY_NOT_IMPLEMENTED: {
message:
'Specific functionality is still in development. (It should be available soon, thank you for understanding.)',
},
SOMETHING_WENT_TERRIBLY_WRONG: {
message: 'Description of an error message...',
},
};

// --- STOP SAFE TO EDIT ---

export const ed = createErrorDescriptor(errors, errorsGroupName);

export default errors;
14 changes: 14 additions & 0 deletions metadata/apps/example-demo-app/hasura-request-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'colors';

const hasuraRequestLogger = (req, res, next) => {
console.log(`[${req.originalUrl}] Request hit!`);
// --------------------------------------------------------------------------------
// Get variables
console.log('This is what we received from Hasura when calling the hook');
console.log(req.body);
console.log(Array(80 + 1).join('-'));
// --------------------------------------------------------------------------------
next();
};

export default hasuraRequestLogger;
24 changes: 24 additions & 0 deletions metadata/apps/example-demo-app/hlambda-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Defines if the app is enabled or not, disabled apps are skipped from importing
enabled: true
# # Defines if we want to use namespace or not
# use_namespace: true # NOT IN USE!
# # Define the namespace name
# namespace_name: 'demo_app' # NOT IN USE!
# Custom environment variables override for our app
env:
HASURA_GRAPHQL_API_ENDPOINT: "http://graphql-engine:8099/v1/graphql"
HASURA_GRAPHQL_ADMIN_SECRET: "hlambda-test"
HLAMBDA_DISABLE_CONSOLE: "false"

#HLAMBDA_ENABLE_ENVIRONMENT_BANNER: "true"
#HLAMBDA_ENVIRONMENT_BANNER_NAME: "Local Hlambda Demo Development"
#HLAMBDA_ENVIRONMENT_BANNER_MESSAGE: "Hello Hlambda Env Banner!"
#HLAMBDA_ENABLE_ENVIRONMENT_BANNER_COLOR: "#eeFF22"

#JSON_STDOUT: true

envForce:
HASURA_GRAPHQL_API_ENDPOINT: "http://graphql-engine:8099/v1/graphql"
HASURA_GRAPHQL_ADMIN_SECRET: "real-password"
SPECIAL_PASSWORD: "value-from-env"
HLAMBDA_DISABLE_CONSOLE: "false"
34 changes: 34 additions & 0 deletions metadata/apps/example-demo-app/router.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import express from 'express';
import asyncHandler from 'express-async-handler';

import { DateTime } from 'luxon';

import hasuraRequestLogger from './hasura-request-logger.js';

import errors from './errors.demo.js';

import requestTimeLogger from '../../../src/utils/requestTimer.js';

// Create express router
const router = express.Router();

router.use('/demo*', hasuraRequestLogger);
router.use('/demo*', requestTimeLogger);

router.get(
'/demo',
asyncHandler((req, res) => {
res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
})
);

router.get(
'/demo-error',
asyncHandler((req, res) => {
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
throw new Error(errors.SOMETHING_WENT_TERRIBLY_WRONG);
// res.send(`Demo app works: ${DateTime.now()} ${process.env.SPECIAL_PASSWORD}`);
})
);

export default router;
21 changes: 21 additions & 0 deletions metadata/apps/example-hasura/errors.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createErrorDescriptor } from 'hlambda';

// --- START SAFE TO EDIT ---

export const errorsGroupName = 'example-hasura-app';

export const errors = {
FUNCTIONALITY_NOT_IMPLEMENTED: {
message:
'Specific functionality is still in development. (It should be available soon, thank you for understanding.)',
},
SOMETHING_WENT_TERRIBLY_WRONG: {
message: 'Description of an error message...',
},
};

// --- STOP SAFE TO EDIT ---

export const ed = createErrorDescriptor(errors, errorsGroupName);

export default errors;
14 changes: 14 additions & 0 deletions metadata/apps/example-hasura/hasura-request-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// import 'colors'; // This is known issue with this package...

const hasuraRequestLogger = (req, res, next) => {
console.log(`[${req.originalUrl}] Request hit!`);
// --------------------------------------------------------------------------------
// Get variables
console.log('This is what we received from Hasura when calling the hook');
console.log(req.body);
console.log(Array(80 + 1).join('-'));
// --------------------------------------------------------------------------------
next();
};

export default hasuraRequestLogger;
4 changes: 4 additions & 0 deletions metadata/apps/example-hasura/hlambda-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
APP_VERSION: "v1.0.0"
envForce:
APP_VERSION: "v1.0.0"
26 changes: 26 additions & 0 deletions metadata/apps/example-hasura/router.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import express from 'express';
import asyncHandler from 'express-async-handler';

// Import our custom request logger
import hasuraRequestLogger from './hasura-request-logger.js';

// Import our errors definition
import errors from './errors.demo.js';

// Create express router
const router = express.Router();

router.use('/hasura-*', hasuraRequestLogger);

router.post(
'/hasura-version',
asyncHandler((req, res) => {
console.log(`${process.env.APP_VERSION}`);
throw new Error(errors.SOMETHING_WENT_TERRIBLY_WRONG);
// res.json({
// version: `${process.env.APP_VERSION}`,
// });
})
);

export default router;
17 changes: 17 additions & 0 deletions metadata/apps/socket-io-app/errors.socket-io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createErrorDescriptor } from 'hlambda';

// --- START SAFE TO EDIT ---

export const errorsGroupName = 'socket-io';

export const errors = {
SOCKET_SERVER_NOT_RUNNING: {
message: 'Socket server is not available.',
},
};

// --- STOP SAFE TO EDIT ---

export const ed = createErrorDescriptor(errors, errorsGroupName);

export default errors;
60 changes: 60 additions & 0 deletions metadata/apps/socket-io-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
html {
color-scheme: dark !important;
}
html, body {
background-color:#181a1b;
}
body { margin: 0; padding-bottom: 3rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body {
border-color: #736b5e;
color: #e8e6e3;
}

#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); }
#input { border: none; padding: 0 1rem; flex-grow: 1; border-radius: 2rem; margin: 0.25rem; }
#input:focus { outline: none; }
#form > button { background: #333; border: none; padding: 0 1rem; margin: 0.25rem; border-radius: 3px; outline: none; color: #fff; }


#messages { list-style-type: none; margin: 0; padding: 0; }
#messages > li { padding: 0.5rem 1rem; }
#messages > li:nth-child(odd) { background: #212425; }
</style>
</head>
<body>
<ul id="messages"></ul>
<form id="form" action="">
<input id="input" autocomplete="off" /><button>Send</button>
</form>
<!-- <script src="https://cdn.socket.io/4.5.0/socket.io.min.js" integrity="sha384-7EyYLQZgWBi67fBtVxw60/OWl1kjsfrPFcaU0pp0nAh+i8FD068QogUvg85Ewy1k" crossorigin="anonymous"></script> -->
<script src="/socket.io/socket.io.js"></script>

<script>
var socket = io();

var messages = document.getElementById('messages');
var form = document.getElementById('form');
var input = document.getElementById('input');

form.addEventListener('submit', function(e) {
e.preventDefault();
if (input.value) {
socket.emit('chat message', input.value);
input.value = '';
}
});

socket.on('chat message', function(msg) {
var item = document.createElement('li');
item.textContent = msg;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
});
</script>
</body>
</html>
71 changes: 71 additions & 0 deletions metadata/apps/socket-io-app/router.static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-disable no-underscore-dangle */
import { fileURLToPath } from 'url';
import path, { dirname } from 'path';

import express from 'express';
import asyncHandler from 'express-async-handler';
import { Server } from 'socket.io';

import { executeWithAdminRights, getEnvValue, isEnvTrue } from 'hlambda';

// // Define constants & errors
// import constants from "./../../constants/constants.index.js";
import errors from './errors.socket-io.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Pull from global scope hlambdaEventEmitter
const { hlambdaEventEmitter } = global;
// --------------------------------------------------------------------------------
// Why do we do this?
// Hlambda emitts event 'server-ready' when the server starts to listen. In that event we have reference to server instance.
// Socket.io needs that server instance reference to work. This is not necessary if you want to run another server on different port.
let io;
const attachSocketIoServer = async (server) => {
// const server = await global.HLAMBDA_SERVER_INSTANCE;
// const io = new Server(server, {});
io = new Server(server, {}); // We want to use io from router.

io.on('connection', (socket) => {
console.log('Socket connected!');

socket.on('chat message', (msg) => {
io.emit('chat message', msg);
});

socket.on('disconnect', () => {
console.log('Socket disconnected!');
});
});
};

// Listen for event.
hlambdaEventEmitter.on('server-ready', (server) => {
console.log(`[hlambdaEventEmitter] 'server-ready' event occurred!`.green);
attachSocketIoServer(server);
});
// --------------------------------------------------------------------------------

// Create express router
const router = express.Router();

// Example of serving static files on route /io
router.use('/io', express.static(path.resolve(__dirname, './public')));

router.get(
'/io/msg',
asyncHandler((req, res) => {
if (typeof io === 'undefined') {
throw new Error(errors.SOCKET_SERVER_NOT_RUNNING);
}

io.emit('chat message', 'Server message!');

res.json({
done: true,
});
})
);

export default router;
4 changes: 4 additions & 0 deletions metadata/apps/static-app-root/hlambda-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Uncomment this for static serving.

#envForce:
# HLAMBDA_DISABLE_INITIAL_ROUTE_REDIRECT: true
1 change: 1 addition & 0 deletions metadata/apps/static-app-root/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x
Loading