-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3.js
More file actions
46 lines (33 loc) · 1.24 KB
/
Copy pathexample3.js
File metadata and controls
46 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const http = require('http');
const url = require('url');
let counterOne = 0;
let counterTwo = 0;
const server = http.createServer((req, res) => {
console.log('Запрос получен');
if (req.url === '/') {
res.writeHead(200, {
'Content-Type':'text/html; charset=UTF-8',
});
counterOne++;
res.end(`<h1>Главная страница</h1>
<a href="/about">Переход на страницу About</a>
<p>Количество посещений страницы ${counterOne}</p>`);
} else if (req.url === '/about') {
res.writeHead(200, {
'Content-Type': 'text/html; charset=UTF-8',
});
counterTwo++;
res.end(`<h1>About</h1>
<a href='/'>Переход на страницу Главная</a>
<p>Количество посещений страницы ${counterTwo}</p>`);
} else {
res.writeHead(404, {
'Content-Type': 'text/html; charset=UTF-8',
});
res.end('<h1>Страница не найдена!</h1>');
}
});
const port = 3000;
server.listen(port, () => {
console.log(`Сервер запущен на порту ${port}`);
});