restify: why serving working directory is not possible?

我怕爱的太早我们不能终老 提交于 2019-12-25 02:39:22

问题


I have a restify server with node.js I use to make some development and tests and to do so, I use serveStatic.

I wonder why I cannot use the following configuration without getting 403 errors:

server.get(/.*/, restify.serveStatic({
  directory: '.',
  default: "index.html"
}));

Although if I make a link to my current dir:

ln -s . serverDir

This will work:

server.get(/.*/, restify.serveStatic({
  directory: './serverDir',
  default: "index.html"
}));

What is the reason for this ? Security ? Bug ? Software or network limitation ?

Is there something I should know or read about serving static files ?


回答1:


Can you user __dirname instead of '.' to indicate the current directory?

server.get(/.*/, restify.serveStatic({
  directory: __dirname,
  default: "index.html"
}));


来源:https://stackoverflow.com/questions/20399648/restify-why-serving-working-directory-is-not-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!