forked from naistangz/Docker_Jenkins_Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·62 lines (42 loc) · 1.26 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
var express = require('express');
var app = express();
var exec = require('child_process').exec;
var mongoose = require('mongoose');
var Post = require('./models/post');
app.set('view engine' , 'ejs');
app.use(express.static('public'));
app.get('/' , function(req , res){
res.render("index");
});
// connect to database
if(process.env.DB_HOST) {
mongoose.connect(process.env.DB_HOST);
app.get("/posts" , function(req,res){
Post.find({} , function(err, posts){
if(err) return res.send(err);
res.render("posts/index" , {posts:posts});
})
});
}
app.get('/fibonacci/:n' , function(req,res){
// high cpu usage function
var value = fibonacci(req.params.n);
res.render("fibonacci" , {index:req.params.n, value:value});
});
// app.get("/hack/:command" , function(req,res){
// var child = exec(req.params.command, function (error, stdout, stderr) {
// res.render("hackable/index", {stdout:stdout, command:req.params.command});
// });
// });
app.listen(3000 , function(){
console.log('Your app is ready and listening on port 3000');
});
// deliberately poorly implemented fibonnaci
function fibonacci(n) {
if(n == 0)
return 0;
if(n == 1)
return 1;
return fibonacci(n - 1) + fibonacci(n - 2);
}
module.exports = app;