Skip to content
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
File renamed without changes.
16 changes: 15 additions & 1 deletion app/public/zadanie01/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<!-- Twój kod -->
<!-- Twój kod -->
<doctype! html>
<head>
<title>Wypełnij formularz</title>
</head>
<body style="text-align: center">
<h1 style="margin-bottom: 20px; font-size: 2rem">Podaj liczby aby sprawdzić dzielniki.<h1/>
<form action="/form" method="post" style="text-align: center; font-size: 2rem">
<input type="number" name="num1" style="width: 100px; font-size: 1.5rem" />
<hr style="width: 100px"/>
<input type="number" name="num2" style="width: 100px; font-size: 1.5rem" />
</br></br>
<button type="submit">Wyślij</button>
</form>
</body>
15 changes: 14 additions & 1 deletion app/public/zadanie02/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<!-- Twój kod -->
<!-- Twój kod -->
<doctype! html>
<head>
<title>Wypełnij formularz</title>
</head>
<body style="text-align: center">
<h1 style="margin-bottom: 20px; font-size: 2rem">Podaj imię i nazwisko<h1/>
<form action="/cookie/set" method="post" style="text-align: center; font-size: 2rem">
<input type="text" name="name" placeholder="Jan" />
<input type="text" name="surname" placeholder="Kowalski" />
</br></br>
<button type="submit">Wyślij</button>
</form>
</body>
11 changes: 11 additions & 0 deletions app/public/zadanieDnia/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<doctype! html />
<head></head>
<body>
<div style="text-align: center">
<form action="/save" method="POST">
<label>Wpisz swój komentarz.</label><br/>
<textarea name="comment"></textarea><br/>
<button type="submit">Dodaj</button>
</form>
</div>
</body>
1 change: 0 additions & 1 deletion app/public/zadanieDnia/index.html

This file was deleted.

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

app.use(express.static(path.join(__dirname, './public/zadanie01/')));
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/form', (req, res) => {
const { num1, num2 } = req.body;
const success = `<h1>BINGO! ${num2} jest dzielnikiem ${num1}</h1>`
const failure = `<h1>${num2} nie jest dzielnikiem ${num1}</h1>`

res.send(num1 % num2 !== 0 ? failure : success); // rozumiem następuje kastowanie na Number ze względu na działanie %?
});

app.listen(3000, () => console.log('serwer stoi na porcie 3000'));
30 changes: 29 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
//Twój kod
//Twój kod
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
const serializeResponse = (value) => `<h1 style='text-align: center'>${value}</h1>`;

app.use(express.static(path.join(__dirname, './public/zadanie02/')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());

app.post('/cookie/set', (req, res) => {
const { name, surname } = req.body;

res.cookie('names', `${name},${surname}`);
res.send(serializeResponse(`Ciastko ustawione: "${name},${surname}"`));
});

app.get('/cookie/show', (req, res) => {
const [ name, surname ] = req.cookies.names.split(',');
res.send(serializeResponse(`User name is: ${name} and surname is: ${surname}`));
});

app.get('/cookie/check', (req, res) => {
res.send(req.cookies ? serializeResponse('Bon a\'petit! There is a cookie here :)') : serializeResponse('Echo... echo... Nothing here.'));
});

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

app.use(express.static(path.join(__dirname, './public/zadanieDnia/')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());

app.post('/save', (req, res) => {
const { comment: newComment } = req.body;
const comments = (req.cookies.comments && JSON.parse(req.cookies.comments)) || [];

comments.push(newComment)
res.cookie('comments', JSON.stringify(comments));
res.send('Komentarz został zapisany. <a href="/">Powrót na stronę główną</a>');
});

app.get('/', (req, res) => {
const comments = JSON.parse(req.cookies.comments);

res.send(`
<ul>
${
comments.map((comment, index) => {
return '<li>' + comment + '</li>';
}).join('')
}
</ul>`)
});

app.listen(3000, () => console.log('serwer stoi na porcie 3000'));
Loading