-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
146 lines (128 loc) · 3.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* Module dependencies.
*/
var express = require('express'),
routes = require('./routes'),
// create server
marlin = module.exports = express.createServer();
// CONFIGURATION
marlin.configure(function () {
marlin.set('views', __dirname + '/views');
// importing the jade html template engine
marlin.set('view engine', 'jade');
marlin.set('jsonp callback', true);
marlin.use(express.bodyParser());
marlin.use(express.methodOverride());
// importing the stylus css template engine
marlin.use(require('stylus').middleware({ src: __dirname + '/public' }));
marlin.use(marlin.router);
marlin.use(express.static(__dirname + '/public'));
});
/**
* Development configuration
* Shows error clearly when in development mode
*/
marlin.configure('development', function(){
marlin.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});
/**
* Production configuration
* Errors do not show in production environment
*/
marlin.configure('production', function () {
marlin.use(express.errorHandler());
});
// ROUTERS
/**
* Home Page Routers
* Gathers all Statisticss and displays them for the user to select one
*/
marlin.get('/', routes.index);
marlin.post('/', function (request, response) {
var project = request.param('projects');
/**
* First page is the "worst page"
* When JavaScript is turned on this is the only page
*/
response.redirect('/projects/' + project);
});
/**
* Statistics Page Router
* Shows stastics for the chosen Statistics
*/
/**
* GET - "worst", fetches the worst performing statistics
* When the user goes to project directly from url or from home page
*/
marlin.get('/projects/:name', routes.project);
/**
* GET - best, fetches the best performing statistics
* When the user submits a form on the project page
*/
marlin.get('/projects/:name/best', routes.project);
/**
* GET - javascript - fetches statistics for javascript performance
*/
marlin.get('/projects/:name/javascript', routes.project);
/**
* POST - best - fetches statistics on the worst performing page
*/
marlin.post('/projects/:name', function (request, response) {
if (request.body.exporting !== undefined){
routes.exporting(request, response);
} else if (request.body.projects !== undefined) {
var project = request.body.projects;
response.redirect('/projects/' + project);
} else {
routes.project(request, response);
}
});
/**
* POST - best - fetches statistics on the best performing page
*/
marlin.post('/projects/:name/best', function (request, response) {
if (request.body.exporting !== undefined){
routes.exporting(request, response);
} else if (request.body.projects !== undefined) {
var project = request.body.projects;
response.redirect('/projects/' + project);
} else {
routes.project(request, response);
}
});
/**
* POST - javascript - fetches statistics on the javascript page
*/
marlin.post('/projects/:name/javascript', function (request, response) {
if (request.body.exporting !== undefined){
routes.exporting(request, response);
} else if (request.body.projects !== undefined) {
var project = request.body.projects;
response.redirect('/projects/' + project);
} else {
routes.project(request, response);
}
});
/**
* AJAX Router
* Handles ajax requests from the client
*/
marlin.get('/:name/ajax', routes.ajax);
/**
* New Report Page Router
* Handles the creation of a new report
*/
marlin.get('/newreport', routes.newReport);
/**
* Generate Build Management Form
* GET
*/
marlin.get('/build', routes.build);
/**
* Generate Build Management Fil
* POST - handles the creation of the build management file
*/
marlin.post('/build', routes.createBuild);
// listen on port 3000
marlin.listen(3000);
//console.log("Express server listening on port %d in %s mode", marlin.address().port, marlin.settings.env);