restify: why serving working directory is not poss

2019-09-02 13:31发布

问题:

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"
}));