Discuss / JavaScript / 直接访问静态文件目录报错问题

直接访问静态文件目录报错问题

Topic source

恋禾梦影

#1 Created at ... [Delete] [Delete and Lock User]

可以加一个是否文件夹的判断,如果是文件夹则禁止访问

if ((await fs.lstat(fp)).isDirectory()){

// 静态文件目录不可访问

ctx.response.body = 'Static directories are not accessible!';

ctx.response.type = 'text/plain';

return;

}

if (await fs.exists(fp)) {

......

}


  • 1

Reply