This commit is contained in:
kogleee
2023-11-08 13:17:48 +03:00
commit 3dbd9654c2
136 changed files with 14736 additions and 0 deletions

20
task13/1/app.js Normal file
View File

@@ -0,0 +1,20 @@
const http = require('http');
const fs = require('fs');
http.createServer(function (request, response) {
console.log(`Запрошенный адрес: ${request.url}`);
// получаем путь после слеша
const filePath = request.url.substr(1);
// смотрим, есть ли такой файл
fs.access(filePath, fs.constants.R_OK, (err) => {
// если произошла ошибка - отправляем статусный код 404
if (err) {
response.statusCode = 404;
response.end('Resourse not found!');
} else {
fs.createReadStream(filePath).pipe(response);
}
});
}).listen(3000, function () {
console.log('Server started at 3000');
});