final
This commit is contained in:
13
task12/1/app.js
Normal file
13
task12/1/app.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var http = require('http');
|
||||
|
||||
http.createServer(function (request, response) {
|
||||
console.log('Url: ' + request.url);
|
||||
console.log('Тип запроса: ' + request.method);
|
||||
console.log(
|
||||
'User-Agent: ' + request.headers['user-agent']
|
||||
);
|
||||
console.log('Все заголовки');
|
||||
console.log(request.headers);
|
||||
|
||||
response.end();
|
||||
}).listen(3000);
|
||||
18
task12/2/app.js
Normal file
18
task12/2/app.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const http = require('http');
|
||||
|
||||
http.createServer(function (request, response) {
|
||||
response.setHeader('Content-Type', 'text/html');
|
||||
response.write('<!DOCTYPE html>');
|
||||
response.write('<html>');
|
||||
response.write('<head>');
|
||||
response.write('<title>Hello Node.js</title>');
|
||||
response.write('<meta charset="utf-8" />');
|
||||
response.write('</head>');
|
||||
response.write('<body>');
|
||||
response.write('<h2>Привет миг</h2>');
|
||||
response.write('<h2>Привет миг</h2>');
|
||||
response.write('<h2>Привет миг</h2>');
|
||||
response.write('</body>');
|
||||
response.write('</html>');
|
||||
response.end();
|
||||
}).listen(3000);
|
||||
19
task12/3/app.js
Normal file
19
task12/3/app.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const http = require('http');
|
||||
|
||||
http.createServer(function (request, response) {
|
||||
response.setHeader(
|
||||
'Content-Type',
|
||||
'text/html; charset=utf-8;'
|
||||
);
|
||||
|
||||
if (request.url === '/home' || request.url === '/') {
|
||||
response.write('<h2>Home</h2>');
|
||||
} else if (request.url == '/about') {
|
||||
response.write('<h2>About</h2>');
|
||||
} else if (request.url == '/contact') {
|
||||
response.write('<h2>Contacts</h2>');
|
||||
} else {
|
||||
response.write('<h2>Not found</h2>');
|
||||
}
|
||||
response.end();
|
||||
}).listen(3000);
|
||||
20
task12/4/app.js
Normal file
20
task12/4/app.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const http = require('http');
|
||||
|
||||
http.createServer(function (request, response) {
|
||||
response.setHeader(
|
||||
'Content-Type',
|
||||
'text/html; charset=utf-8;'
|
||||
);
|
||||
|
||||
if (request.url === '/loli') {
|
||||
response.statusCode = 302; // временная переадресация
|
||||
// на адрес localhost:3000/newpage
|
||||
response.setHeader('Location', '/newpage');
|
||||
} else if (request.url == '/newpage') {
|
||||
response.write('New address');
|
||||
} else {
|
||||
response.write('Not Found');
|
||||
response.statusCode = 404; // адрес не найден
|
||||
}
|
||||
response.end();
|
||||
}).listen(3000);
|
||||
Reference in New Issue
Block a user