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
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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.static('./public/zadanie01'));

app.post('/result', (req, res) => {
const {firstNumb,secondNumb} = req.body;
let result = '';
if(parseInt(firstNumb) % parseInt(secondNumb)){
result = `${firstNumb} jest dzielnikiem ${secondNumb}`;
}else{
result = `${firstNumb} nie jest dzielnikiem ${secondNumb}`;
}
res.send(result);
});

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

app.post('/cookie/set',(req,res)=>{
const {name} = req.body;
res.cookie('newName', name,{
maxAge : 31536000000,
});
res.send('Zapisano imię: ' + name);
});
app.get('/cookie/show',(req,res)=>{
const myCookie = req.cookies.newName;
res.send('Zapisane imię: ' + myCookie);
});
app.get('/cookie/check',(req,res)=>{
const myCookie = req.cookies.newName;
if(myCookie === undefined){
res.send('Brak zapisanego imienia!');
} else{
res.send('Zapisane imię: '+myCookie);
}
});
app.listen(3000,()=>{
console.log('Serwer uruchomiony na porcie 3000');
});
36 changes: 35 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
//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({extended:false}));
app.use(express.static('./public/zadanieDnia/'))

app.post('/save', (req, res) => {
const allComments = addComment(req.cookies.comments, req.body.comment)

res.cookie('comments', allComments, {
maxAge : 31536000000,
});
res.send('Zapisano komentarz <a href="/">Powrót do strony głównej</a>');
});

app.get('/', (req, res) => {
const comments = readComments(req.cookies.comments);
res.send(`${comments}</br><a href="/add.html">Dodaj nowy komentarz</a>`);
});

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

function addComment(commentsCookieValue, newComment) {
const comments = readComments(commentsCookieValue);
comments.push(newComment);
return JSON.stringify(comments);
}
function readComments(commentsCookieValue) {
return commentsCookieValue ? JSON.parse(commentsCookieValue) : [];
}