DASHA
This commit is contained in:
25
Отправка статических файлов/app.js
Normal file
25
Отправка статических файлов/app.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
|
||||
http.createServer(function (request, response) {
|
||||
console.log(`Запрошенный адрес: ${request.url}`);
|
||||
if (request.url.startsWith('/public/')) {
|
||||
// получаем путь после слеша
|
||||
const filePath = request.url.substr(1);
|
||||
fs.readFile(filePath, function (error, data) {
|
||||
if (error) {
|
||||
response.statusCode = 404;
|
||||
response.end('Resourse not found!');
|
||||
} else {
|
||||
response.setHeader(
|
||||
'Content-Type',
|
||||
'text/html'
|
||||
);
|
||||
response.end(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// во всех остальных случаях отправляем строку hello world!
|
||||
response.end('Hello World!');
|
||||
}
|
||||
}).listen(3000);
|
||||
11
Отправка статических файлов/public/about.html
Normal file
11
Отправка статических файлов/public/about.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>О сайте</title>
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>О сайте</h1>
|
||||
</body>
|
||||
<html></html>
|
||||
</html>
|
||||
11
Отправка статических файлов/public/index.html
Normal file
11
Отправка статических файлов/public/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Главная</title>
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Главная</h1>
|
||||
</body>
|
||||
<html></html>
|
||||
</html>
|
||||
Reference in New Issue
Block a user