Я пытался подключить код из: https://github.com/wimagguc/nodejs-static-http-with-gzip/blob/master/http-with-gzip.js Каталоги и файл Server.js Я внес изменения, добавив код:
path.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
var raw = fs.createReadStream(filePath);
if (acceptEncoding.match(/\bdeflate\b/)) {
response.writeHead(200, { 'content-encoding': 'deflate' });
raw.pipe(zlib.createDeflate()).pipe(response);
} else if (acceptEncoding.match(/\bgzip\b/)) {
response.writeHead(200, { 'content-encoding': 'gzip' });
raw.pipe(zlib.createGzip()).pipe(response);
} else {
response.writeHead(200, {});
raw.pipe(response);
}
}
});
}
else {
response.writeHead(404);
response.end();
}
в server.js по адресу:
app.get('/', (req, res) => {
//this place
res.render('home.hbs', {
pageTitle: 'Home Page',
welcomeMess: 'Welcome to my Site'
})
}); ошибка: path.exists не является функцией. но я не мог понять то же самое и сломал свое приложение.
я надеялся получить файл, заархивированный gzip. Я использую экспресс для работы с сервером
Пожалуйста, добавьте больше деталей, чтобы вам было легче помочь. Что вы пробовали? Каков был результат? Что вы ожидали?