blob: d2acfec2464a0bed1d647cb450535c3c25db54ed [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001var express = require('express');
2var path = require('path');
3var favicon = require('serve-favicon');
4var logger = require('morgan');
5var cookieParser = require('cookie-parser');
6var bodyParser = require('body-parser');
7var serveIndex = require('serve-index');
8var serveStatic = require('serve-static')
9
10var routes = require('./routes/index');
11var users = require('./routes/users');
12var dgeusers = require('./dgeusers.json');
13console.log("Read these dgeusers: " + JSON.stringify(dgeusers));
14
15var app = express();
16
17// view engine setup
18app.set('views', path.join(__dirname, 'views'));
19app.set('view engine', 'ejs');
20
21// uncomment after placing your favicon in /public
22//app.use(favicon(__dirname + '/public/favicon.ico'));
23app.use(logger('dev'));
24app.use(bodyParser.json());
25app.use(bodyParser.urlencoded({ extended: false }));
26app.use(cookieParser());
27app.use(express.static(path.join(__dirname, 'public')));
28
29
30// set up static serving and directory listings for each user's lib/flows directory
31dgeusers.forEach( function(dgeuser) {
32 console.log("Setting up static serving for " + dgeuser);
33 var sDir = "../users/" + dgeuser + '/flows/shared';
34 console.log("sDir" + sDir);
35 app.use('/listFlows/'+dgeuser+'/flows/shared', serveIndex(sDir, {'view': 'details', 'icons': true}))
36});
37
38app.use('/', routes);
39app.use('/users', users);
40
41// catch 404 and forward to error handler
42app.use(function(req, res, next) {
43 var err = new Error('Not Found');
44 err.status = 404;
45 next(err);
46});
47
48// error handlers
49
50// development error handler
51// will print stacktrace
52if (app.get('env') === 'development') {
53 app.use(function(err, req, res, next) {
54 res.status(err.status || 500);
55 res.render('error', {
56 message: err.message,
57 error: err
58 });
59 });
60}
61
62// production error handler
63// no stacktraces leaked to user
64app.use(function(err, req, res, next) {
65 res.status(err.status || 500);
66 res.render('error', {
67 message: err.message,
68 error: {}
69 });
70});
71
72
73module.exports = app;