-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (36 loc) · 1.08 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
const express = require("express");
const app = express();
const nunjucks = require("nunjucks");
const tarefas = [];
nunjucks.configure("views", { autoescape: true, express: app, watch: true });
app.set("view engine", "njk");
app.use(express.urlencoded({ extended: false }));
// Middlewares
app.use(express.static("./views")); // mapeando arquivos estaticos com express
app.get("/", (req, res) => {
return res.redirect("/clock");
});
app.get("/clock", (req, res) => {
return res.render("home");
});
app.get("/tasks", (req, res) => {
return res.render("tasks", { tarefas });
});
// iniciando próxima task
app.post("/next-task", (req, res) => {
var task = req.body;
if (task != undefined) {
var times = [];
task.elapsedTime.split(":").forEach(a => {
times.push(a * 1);
});
if (times[2] > 0) {
tarefas.push({ timeElapsed: task.elapsedTime });
return res.send("ok");
}
}
return res.send("Error: not received taks with spended time.");
});
// excuta requisições na porta 3000
app.listen(3000);
console.log("Node server running on port 3000");