const express = require("express")
const app = express()
const PORT = 3000
app.use(express.urlencoded({
extended: true
}));
app.get("/", function (req, res) {
let samochody = ['audi', 'opel', 'dyliżans', 'tramwaj', 'ford (1.0 ecoboost xd)', 'elektryczny smart']
html =
`
Samochody
'
res.send(html)
})
app.post("/handle_form", function (req, res) {
let stany_aut = {
"nowe": 0,
"używane": 0,
"powypadkowe": 0
}
for (let i = 0; i < Object.keys(req.body).length; i++) {
switch (Object.values(req.body)[i]) {
case "nowy":
stany_aut.nowe += 1
break
case "uzywany":
stany_aut.używane += 1
break
case "powypadkowy":
stany_aut.powypadkowe += 1
break
}
}
res.send(stany_aut)
})
app.use(express.static('static'))
app.listen(PORT, function () {
console.log("Serwer uruchomiony na porcie " + PORT)
})