-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (71 loc) · 1.79 KB
/
app.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
var isLocal = false;
var express = require('express');
var fs = require('fs');
var stylus = require('stylus');
var nib = require('nib');
var jade = require('jade');
var where = require('node-where');
var app = express();
function compile(str, path) {
return stylus(str)
.set('filename', path)
.set('compress', true)
.use(nib());
}
app.use(function(req, res, next){
if (req.path.indexOf('/public/') != -1) return next();
where.is(req.ip, function(err, result) {
if (result){
var d = new Date();
var str = d.toUTCString() + '\t' +
(req.ip || 'ip') + '\tfrom\t ' +
(result.attributes.city || 'city') + '\t' +
(result.attributes.region || 'region') + '\t' +
(result.attributes.country || 'country') + '\trequests\t' +
req.path;
console.log(str);
str += '\n';
fs.appendFile(__dirname + '/portfolio.log', str, function(err){
if (err) console.log(err);
});
} else {
try{
console.log(err);
} catch (e){
}
}
});
next();
});
app.use(stylus.middleware({
src: __dirname + '/public'
, compile: compile
}));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use('/public', express.static(__dirname + '/public'));
app.get('/resume', function(req, res){
var resume=__dirname + "/public/JustinCarrus.pdf";
fs.readFile(resume, function (err,data){
res.contentType("application/pdf");
res.send(data);
});
});
app.get('/(:page)?', function(req, res){
if (!req.params.page){
return res.render('index', {});
}
res.render(req.params.page, {}, function(err, html){
if(err){
return res.status(404).send("404 Page not found");
}
res.send(html);
});
});
if (isLocal){
app.listen(3000, function() {
console.log('listening on 3000');
});
} else {
module.exports = app;
}