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

rozwiązania #4

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
test.js
1 change: 0 additions & 1 deletion app/.gitignore

This file was deleted.

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

app.get('/:num1/:num2', (req, res) => {
const num1 = parseInt(req.params.num1);
const num2 = parseInt(req.params.num2);
res.send(`${num1} + ${num2} = ${num1 + num2}`);
});

app.listen(3000, () => {
console.log('serwer stoi na porcie 3000');
});
23 changes: 22 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
//Twój kod
//Twój kod
const express = require('express');
const app = express();

let CACHE = { NAMES: [] };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ciekawe. Podoba mi się takie czytelne rozwiązanie :)


app.get('/name/set/:imie', (req, res) => {
CACHE.NAMES.push(req.params.imie);
res.send(`<h1 style="text-align: center">Imię "${CACHE.NAMES[CACHE.NAMES.length - 1]}" zapisano do cache aplikacji.</h1>`);
});

app.get('/name/show', (req, res) => {
const formattedName = CACHE.NAMES.length > 1 ? 'Imiona' : 'Imię';
res.send(`<h1 style="text-align: center">${formattedName} z cache'a aplikacji:</h1><h2 style="text-align: center">${CACHE.NAMES}</h2>`)
});

app.get('/name/check', (req, res) => {
const isEmpty = CACHE.NAMES.length !== 0 ? 'Coś tam jest!' : 'Cache jest pusty';
res.send(`<h1 style="text-align: center">${isEmpty}</h1>`);
});

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

let CACHE = {
yes: 0,
no: 0
}

app.use(express.static(path.join(__dirname, 'public/zadanieDnia/')));

app.get('/votes/check', (req, res) => {
const results = `
<h1 style="text-align: center">Głosy na tak: ${CACHE.yes} :)</h1>
<h1 style="text-align: center">Głosy na nie: ${CACHE.no} :(</h1>
`;

res.send(results);
});

app.get('/vote/:vote', (req, res) => {
const yesno = req.params.vote;
CACHE[yesno] += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, brawo!


res.send('<h1 style="text-align: center">"Dziękujemy za głos!</h1>');
});

app.get('/manual/route', (req, res) => {
console.log(req.headers);
})

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