aboutsummaryrefslogtreecommitdiffstats
path: root/dgbuilder/dgeflows/src
diff options
context:
space:
mode:
Diffstat (limited to 'dgbuilder/dgeflows/src')
-rw-r--r--dgbuilder/dgeflows/src/app.js70
-rw-r--r--dgbuilder/dgeflows/src/error.ejs3
-rw-r--r--dgbuilder/dgeflows/src/index.ejs16
-rw-r--r--dgbuilder/dgeflows/src/index.js28
-rw-r--r--dgbuilder/dgeflows/src/package.json19
-rw-r--r--dgbuilder/dgeflows/src/users.js9
6 files changed, 145 insertions, 0 deletions
diff --git a/dgbuilder/dgeflows/src/app.js b/dgbuilder/dgeflows/src/app.js
new file mode 100644
index 00000000..888ab567
--- /dev/null
+++ b/dgbuilder/dgeflows/src/app.js
@@ -0,0 +1,70 @@
+var express = require('express');
+var path = require('path');
+var favicon = require('serve-favicon');
+var logger = require('morgan');
+var cookieParser = require('cookie-parser');
+var bodyParser = require('body-parser');
+var serveIndex = require('serve-index');
+var serveStatic = require('serve-static')
+
+var routes = require('./routes/index');
+var users = require('./routes/users');
+var dgeusers = require('./dgeusers.json');
+console.log("Read these dgeusers: " + JSON.stringify(dgeusers));
+
+var app = express();
+
+// view engine setup
+app.set('views', path.join(__dirname, 'views'));
+app.set('view engine', 'ejs');
+
+// uncomment after placing your favicon in /public
+//app.use(favicon(__dirname + '/public/favicon.ico'));
+app.use(logger('dev'));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({ extended: false }));
+app.use(cookieParser());
+app.use(express.static(path.join(__dirname, 'public')));
+
+
+// set up static serving and directory listings for each user's lib/flows directory
+dgeusers.forEach( function(dgeuser) {
+ app.use('/listFlows/'+dgeuser+'/lib/flows', serveIndex('../' + dgeuser+'/lib/flows', {'view': 'details', 'icons': true}))
+});
+
+app.use('/', routes);
+app.use('/users', users);
+
+// catch 404 and forward to error handler
+app.use(function(req, res, next) {
+ var err = new Error('Not Found');
+ err.status = 404;
+ next(err);
+});
+
+// error handlers
+
+// development error handler
+// will print stacktrace
+if (app.get('env') === 'development') {
+ app.use(function(err, req, res, next) {
+ res.status(err.status || 500);
+ res.render('error', {
+ message: err.message,
+ error: err
+ });
+ });
+}
+
+// production error handler
+// no stacktraces leaked to user
+app.use(function(err, req, res, next) {
+ res.status(err.status || 500);
+ res.render('error', {
+ message: err.message,
+ error: {}
+ });
+});
+
+
+module.exports = app;
diff --git a/dgbuilder/dgeflows/src/error.ejs b/dgbuilder/dgeflows/src/error.ejs
new file mode 100644
index 00000000..7cf94edf
--- /dev/null
+++ b/dgbuilder/dgeflows/src/error.ejs
@@ -0,0 +1,3 @@
+<h1><%= message %></h1>
+<h2><%= error.status %></h2>
+<pre><%= error.stack %></pre>
diff --git a/dgbuilder/dgeflows/src/index.ejs b/dgbuilder/dgeflows/src/index.ejs
new file mode 100644
index 00000000..c207c7bc
--- /dev/null
+++ b/dgbuilder/dgeflows/src/index.ejs
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= title %></title>
+ <link rel='stylesheet' href='/stylesheets/style.css' />
+ </head>
+ <body>
+ <center>
+ <h1><%= title %></h1>
+ <p>Select user</p>
+ <% dgeusers.forEach( function(dgeuser) { %>
+ <p><a href='listFlows/<%= dgeuser %>/lib/flows'><%= dgeuser %></a></p>
+ <% }); %>
+ </center>
+ </body>
+</html>
diff --git a/dgbuilder/dgeflows/src/index.js b/dgbuilder/dgeflows/src/index.js
new file mode 100644
index 00000000..96a08659
--- /dev/null
+++ b/dgbuilder/dgeflows/src/index.js
@@ -0,0 +1,28 @@
+var express = require('express');
+var router = express.Router();
+var dgeusers = require('../dgeusers.json');
+var path = require('path');
+var _ = require('lodash');
+
+/* GET home page. */
+router.get('/', function(req, res, next) {
+ console.log("In route and dgeusers is: " + JSON.stringify(dgeusers));
+ res.render('index', { title: 'DGE Flow Browser', dgeusers: dgeusers });
+});
+
+// GET a flow file
+router.get('/listFlows/:dgeuser/:lib/:flows/:fileName', function(req, res, next) {
+ console.log("Getting a file...");
+ console.dir(req.params);
+ // make sure we like this user
+ if ( !(_.includes(dgeusers, req.params.dgeuser)) ) {
+ console.log("We don't like this user!");
+ res.send("No!");
+ return;
+ }
+ filePath=path.join(__dirname, '../..', req.params.dgeuser, 'lib', 'flows', req.params.fileName);
+ console.log("Getting this file: " + filePath);
+ res.sendFile(filePath);
+});
+
+module.exports = router;
diff --git a/dgbuilder/dgeflows/src/package.json b/dgbuilder/dgeflows/src/package.json
new file mode 100644
index 00000000..893aeb9d
--- /dev/null
+++ b/dgbuilder/dgeflows/src/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "dgeflows",
+ "version": "0.0.0",
+ "private": true,
+ "scripts": {
+ "start": "node ./bin/www"
+ },
+ "dependencies": {
+ "body-parser": "~1.10.2",
+ "cookie-parser": "~1.3.3",
+ "debug": "~2.1.1",
+ "ejs": "~2.2.3",
+ "express": "~4.11.1",
+ "morgan": "~1.5.1",
+ "serve-favicon": "~2.2.0",
+ "serve-index": "^1.6.2",
+ "serve-static": "^1.9.1"
+ }
+}
diff --git a/dgbuilder/dgeflows/src/users.js b/dgbuilder/dgeflows/src/users.js
new file mode 100644
index 00000000..623e4302
--- /dev/null
+++ b/dgbuilder/dgeflows/src/users.js
@@ -0,0 +1,9 @@
+var express = require('express');
+var router = express.Router();
+
+/* GET users listing. */
+router.get('/', function(req, res, next) {
+ res.send('respond with a resource');
+});
+
+module.exports = router;