This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
121 lines (101 loc) · 3.63 KB
/
main.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
//The application server
//All the filtering and data processing happens here.
//Processes the ```data-sources.json``` and ```data-description.json``` files
//Dependencies
var express = require("express"),
routes = require("./routes"),
user = require("./routes/user"),
rest = require("./routes/rest"),
visualizationRoutes = require("./routes/visualizations"),
process = require("process"),
compress = require("compression")(),
path = require("path"),
favicon = require("serve-favicon"),
morgan = require("morgan"),
bodyParser = require("body-parser"),
methodOverride = require("method-override"),
cookieParser = require("cookie-parser"),
cookieSession = require("cookie-session");
//App modules
var dataSource = require("./modules/dataSource"),
dataDescription = require("./modules/dataDescription"),
interactiveFilters = require("./modules/interactiveFilters"),
visualization = require("./modules/visualization");
var app = express();
// all environments
app.set("port", process.env.PORT || 3001);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");
//app.use(favicon());
app.use(morgan("dev"));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(methodOverride());
app.use(compress);
app.use(cookieParser("S3CRE7"));
app.use(cookieSession({
name: 'session',
keys: ['key1', 'key2']
}));
app.use(express.static(path.join(__dirname, "public")));
app.use("/images",express.static(path.join(__dirname, "images")));
app.use("/configs",express.static(path.join(__dirname, "config")));
//
//#### init()
//Initializtion function
//
function init(callback){
dataSource.init();
dataDescription.init();
interactiveFilters.init();
visualization.init();
dataSource.loadData(function(dataSourceName, data){
if(!data){
console.log("Error! Couldn't fetch the data.");
process.exit(1);
}
console.log("Loaded Data");
interactiveFilters.applyCrossfilter(data, dataSourceName);
visualization.applyCrossfilter(dataSourceName);
visualizationRoutes.heatInit(dataSourceName);
console.log("Initialized filters");
listen(callback);
});
}
//
// listen to the specified port for HTTP requests
//
function listen(callback){
console.log("listening...");
var port = app.settings["port"];
app.listen(port,function() {
console.log("listening to port "+port);
callback();
});
}
function handleState(req, res, next){
res.writeHead(200, { "content-type": "application/json" });
}
// Listen for filtering requests on ```/data```
app.use("/data",routes.handleFilterRequest);
app.use("/populationInfo", routes.populationInfo);
app.use("/dataTable/next", routes.tableNext);
app.use("/state", handleState);
app.use("/save", routes.save);
app.use("/heat", visualizationRoutes.heat);
app.use("/imageGrid/next", routes.imageGridNext);
app.use("/statistics", routes.getStatistics);
app.post('/uploadDataSource', rest.postDataSource);
app.post('/uploadVisualization', rest.postVisualization);
app.post('/uploadInteractiveFilters', rest.postInteractiveFilters);
// Change this to the static directory of the index.html file
app.get("/", routes.index);
app.get("/rest/json", rest.index);
app.get("/users", user.list);
app.get("/config/dataDescription", rest.getDataDescriptionConfig);
app.get("/config/interactiveFilters", rest.getInteractiveFiltersConfig);
app.get("/config/visualization", rest.getVisualizationConfig);
app.get("/config/dashboard", rest.getDashboardConfig);
exports.init = init;