-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (42 loc) · 1.32 KB
/
server.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
// Module Dependencies
var express = require('express'),
app = express();
http = require('http'),
path = require('path'),
fs = require("fs"),
_ = require('lodash'),
dir = require('node-dir');
module.exports = function(conf){
var conf = _.extend({
dir : path.join(__dirname, 'app'),
port : 8080
},conf);
app.use(require('connect-livereload')());
app.use(express.static(conf.dir));
app.set("views", conf.dir)
app.engine('jade', require('jade').__express);
app.get("/", function(req, res, next) {
dir.paths(conf.dir, function(err,paths){
if(err)
res.send(500);
var filtered_dirs = paths.dirs.filter(excluded_folders).map(relative_dirs);
res.render("index.jade", {dirs:filtered_dirs});
})
});
var relative_dirs = function(curr) {
return path.relative(conf.dir, curr);
}
var excluded_folders = function(val) {
return !val.match("bower_components");
}
app.get("/json", function(req, res, next) {
var readable = fs.createReadStream("app/iris.json");
readable.pipe(res);
});
app.get("/csv", function(req, res, next) {
var readable = fs.createReadStream("app/iris.csv");
readable.pipe(res);
});
app.listen(conf.port);
console.log("Server started in http://localhost:" + conf.port);
}