-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (49 loc) · 1.34 KB
/
app.js
File metadata and controls
58 lines (49 loc) · 1.34 KB
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
var express = require("express");
var hbs = require('hbs');
var favicon = require('serve-favicon');
var fs = require('fs');
var app = express();
var v_path = __dirname + '/views/';
var p_path = __dirname + '/public/';
var post_location = p_path + 'build/';
app.use(favicon(p_path + 'images/favicon.ico'));
app.set('view engine', 'hbs');
hbs.registerPartials(__dirname + '/views/partials');
app.use(express.static(p_path));
app.use(express.static(__dirname+'/css/'));
var posts = getPosts();
app.get("/", function(req,res){
res.render('index', {work: posts.works, edu: posts.edus, utak: posts.utaks});
})
function getPosts() {
var works = [];
var edus = [];
var utaks = [];
fs.readdir(post_location, function(err,files){
if(err) throw err;
files.forEach(function(file){
switch(file.split(':')[0]) {
case 'work' :
works.unshift(fs.readFileSync(post_location + file, 'utf8'));
break;
case 'edu' :
edus.unshift(fs.readFileSync(post_location + file, 'utf8'));
break;
case 'utak' :
utaks.unshift(fs.readFileSync(post_location + file, 'utf8'));
break;
case '.DS_Store':
break;
}
});
});
return {
works: works,
edus: edus,
utaks: utaks
};
}
var port = process.env.PORT || 3000;
app.listen(port, function(){
console.log("Live at Port " + port);
});