-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
044fca5
commit 4a82e3f
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
/*--------------------------------------------------------------------------------------------------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |