6 technically incorrect
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const data = require("./models/bilder");
|
||||
const url = require("url")
|
||||
|
||||
app.set("view engine", "ejs");
|
||||
app.set("views", "views");
|
||||
|
||||
// Hier Code ergaenzen!
|
||||
const router = express.Router();
|
||||
app.use(express.static("public"));
|
||||
router.get("/", function(req,res){
|
||||
const param = url.parse(req.url, true).query;
|
||||
var current = Number(param.num) || 0;
|
||||
res.render("home",{
|
||||
current: current,
|
||||
next: data.vor(current),
|
||||
prev: data.zurueck(current),
|
||||
bild : data.holeStartBild(current),
|
||||
});
|
||||
});
|
||||
app.use(router);
|
||||
|
||||
app.listen(8910);
|
||||
@@ -18,4 +18,27 @@ const bilder = [
|
||||
},
|
||||
];
|
||||
|
||||
function holeStartBild(num){
|
||||
return bilder[num];
|
||||
}
|
||||
|
||||
function vor(current){
|
||||
var next = current + 1;
|
||||
if(next >= bilder.length){
|
||||
next = 0;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function zurueck(current){
|
||||
var prev = current - 1;
|
||||
if(prev < 0){
|
||||
prev = bilder.length - 1;
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
// Hier den Code ergaenzen!
|
||||
module.exports.bilder = bilder;
|
||||
module.exports.holeStartBild = holeStartBild;
|
||||
module.exports.vor = vor;
|
||||
module.exports.zurueck = zurueck;
|
||||
@@ -4,6 +4,7 @@
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"run": "node app.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
|
||||
@@ -18,9 +18,13 @@
|
||||
|
||||
<body>
|
||||
<!-- Hier den Code ergaenzen -->
|
||||
<figure>
|
||||
<figcaption><%= bild.beschreibung %></figcaption>
|
||||
<img src="<%= `img/${bild.dateiname}` %>">
|
||||
</figure>
|
||||
|
||||
<a href="zurueck">Zurück</a> |
|
||||
<a href="vor">Vor</a>
|
||||
<a href="/?num=<%= prev %>">Zurück</a> |
|
||||
<a href="/?num=<%= next %>">Vor</a>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user