Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dzień 6 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
19 changes: 18 additions & 1 deletion app/public/zadanie01/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
<!-- Twój kod -->
<!-- Twój kod -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3>Czy liczba b jest dzielnikiem liczby a</h3>
<form action="/modulo" method="post">
Liczba a <input type="text" name="a"><br>
Liczba b <input type="text" name="b"><br>
<button type="submit">Wyślij</button>
</form>
</body>
</html>
18 changes: 17 additions & 1 deletion app/public/zadanie02/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
<!-- Twój kod -->
<!-- Twój kod -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="/cookie/set" method="post">
Podaj imię <input type="text" name="name"><br>
<button type="submit">Wyślij</button>
</form>
<a href="/cookie/show" method="get" >Pokaż imię</a>
</body>
</html>
17 changes: 17 additions & 0 deletions app/public/zadanieDnia/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Twój kod -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Forum</title>
</head>
<body>
<form action="/save" method="post">
<textarea name="comment"></textarea><br><hr>
<button type="submit">SKOMENTUJ</button>
</form>

</body>
</html>
1 change: 0 additions & 1 deletion app/public/zadanieDnia/index.html

This file was deleted.

21 changes: 20 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
//Twój kod
//Twój kod
const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.use(bodyParser.urlencoded());
app.use(bodyParser());

app.use(express.static('public/zadanie01/'))

app.post('/modulo', (req, res) => {
const {a,b} = req.body; //Pamiętasz ten skrótowy zapis z ES6?
const modulo = ((parseInt(a) % parseInt(b))===0)? 'jest dzielnikiem liczby: ' : 'nie jest dzielnikiem liczby: '
res.send(`
liczba ${b} ${modulo} ${a}`);
});

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
25 changes: 24 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
//Twój kod
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

const app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded());
app.use(express.static('./public/zadanie02/'));

app.post('/cookie/set', (req, res) => {
res.cookie('name', req.body.name, {maxAge : 31536000000});
res.send('Imię: ' + req.body.name);
});

app.get('/cookie/check', (req, res) => {
const imie = req.cookies.name === undefined ? res.cookies.name : 'nie';
res.send(`Imię ${imie} zostało zapisane w ciastku.`);
});

app.get('/cookie/show', (req, res) => {res.send('Zapisane imię: ' + req.cookies.name); });

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
62 changes: 61 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
//Twój kod
//Twój kod
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

const app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded());
app.use(express.static('./public/zadanieDnia/'));


function addComment(commentsCookieValue, newComment) {
let comments = readComments(commentsCookieValue);
comments = [newComment, ...comments];
comments.join(" ");
return JSON.stringify(comments);
}

function readComments(commentsCookieValue) {
return commentsCookieValue ? JSON.parse(commentsCookieValue) : [];
}


app.use(express.static('./public/zadanieDnia/'));



app.get('/', (req, res) => {
console.log(JSON.stringify(req.cookies.comments));
const comments = readComments(req.cookies.comments);

const commentList = comments.map(comment=>{return `<li><hr>${comment}</li>`})
res.send( `<ul>${commentList}</ul><hr><a href="/add.html">Dodaj nowy komentarz</a>
<br>
<hr>
<a href='/clear'>USUŃ KOMENTARZE</a>
<style>
*{
list-style-type: none;
}
</style>
`);
});

app.post('/save', (req, res) => {
const comments = addComment(req.cookies.comments, req.body.comment);
res.cookie('comments', comments, {
maxAge: 31536000000
});
res.send(`Zapisano nowy komentarz.
<a href="/">wróć</a>`);
});

app.get('/clear', (req, res) => {
res.clearCookie('comments');
res.send(`Wszystko usunięte <a href="/">wróć</a>`);
});

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
Loading