Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
flambert70 committed Dec 8, 2023
1 parent 044fca5 commit 4a82e3f
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
137 changes: 137 additions & 0 deletions ami-pipeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env node
/*--------------------------------------------------------------------------------------------------------------------*/

import fs from 'fs';
import url from 'url';
import path from 'path';

/*--------------------------------------------------------------------------------------------------------------------*/

import http from 'http';
import https from 'https';
import express from 'express';
import nodeRed from 'node-red';

/*--------------------------------------------------------------------------------------------------------------------*/
/* CONSTANTS */
/*--------------------------------------------------------------------------------------------------------------------*/

const DIR_PATH = path.dirname(url.fileURLToPath(import.meta.url));

/*--------------------------------------------------------------------------------------------------------------------*/

const NODE_RED_SETTINGS = {
uiPort: 1880,
uiHost: '0.0.0.0',
httpNodeRoot: '/api',
httpAdminRoot: '/',
userDir: path.join(DIR_PATH, 'data', 'node-red'),
editorTheme: {
page: {
css: path.join(DIR_PATH, 'node_modules', 'node-red-contrib-ami', 'style', 'ami.css'),
},
header: {
title: 'pipeline',
image: path.join(DIR_PATH, 'node_modules', 'node-red-contrib-ami', 'style', 'logo.png'),
},
login: {
image: path.join(DIR_PATH, 'node_modules', 'node-red-contrib-ami', 'style', 'login.png'),
},
palette: {
categories: ['AMI', 'subflows', 'common', 'function', 'network', 'sequence', 'parser', 'storage'],
},
},
};

/*--------------------------------------------------------------------------------------------------------------------*/
/* APPLICATION */
/*--------------------------------------------------------------------------------------------------------------------*/

const app = express();

const isSecured = process.argv.slice(2).includes('--secured');

/*--------------------------------------------------------------------------------------------------------------------*/

let httpsServer;

if(isSecured)
{
/*----------------------------------------------------------------------------------------------------------------*/

const HTTPS_SETTINGS = {};

const KEY_PATH = path.join(DIR_PATH, 'data', 'key.pem');
const CERT_PATH = path.join(DIR_PATH, 'data', 'cert.pem');

/*----------------------------------------------------------------------------------------------------------------*/

try
{
HTTPS_SETTINGS['key'] = fs.readFileSync(KEY_PATH, 'utf8');
}
catch(e)
{
console.error(`Error opening "${KEY_PATH}"`);

process.exit(1);
}

/*----------------------------------------------------------------------------------------------------------------*/

try
{
HTTPS_SETTINGS['cert'] = fs.readFileSync(CERT_PATH, 'utf8');
}
catch(e)
{
console.error(`Error opening "${CERT_PATH}"`);

process.exit(1);
}

/*----------------------------------------------------------------------------------------------------------------*/

httpsServer = https.createServer(HTTPS_SETTINGS, app);

/*----------------------------------------------------------------------------------------------------------------*/
}
else
{
/*----------------------------------------------------------------------------------------------------------------*/

httpsServer = http.createServer(app);

/*----------------------------------------------------------------------------------------------------------------*/
}

/*--------------------------------------------------------------------------------------------------------------------*/
/* NOD-RED */
/*--------------------------------------------------------------------------------------------------------------------*/

nodeRed.init(httpsServer, NODE_RED_SETTINGS);

/*--------------------------------------------------------------------------------------------------------------------*/
/* ROUTES */
/*--------------------------------------------------------------------------------------------------------------------*/

app.use(NODE_RED_SETTINGS.httpAdminRoot, nodeRed.httpAdmin);

app.use(NODE_RED_SETTINGS.httpNodeRoot, nodeRed.httpNode);

/*--------------------------------------------------------------------------------------------------------------------*/
/* LOOP */
/*--------------------------------------------------------------------------------------------------------------------*/

httpsServer.listen(1880);

/*--------------------------------------------------------------------------------------------------------------------*/

nodeRed.start().catch((e) => {

console.log(`Error starting frontend: ${e}`);

process.exit(1);
});

/*--------------------------------------------------------------------------------------------------------------------*/
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ami-pipeline",
"version": "1.0.0",
"description": "Node-RED-based pipeline for AMI",
"main": "ami-pipeline.js",
"type": "module",
"scripts": {
"ami-pipeline-http": "node ami-pipeline.js",
"ami-pipeline-https": "node ami-pipeline.js --secured"
},
"dependencies": {
"express": "^4.18.2",
"node-red": "^3.1.3",
"node-red-contrib-ami": "github:ami-team/node-red-contrib-ami"
}
}

0 comments on commit 4a82e3f

Please sign in to comment.