serving static files with restify (node.js)

后端 未结 3 1732
臣服心动
臣服心动 2021-02-02 10:35

I have the following code:

app.js

[...]

server.get(/\\/docs\\/public\\/?.*/, restify.serveStatic({
  directory: \'./public\'
}));

server.listen(1337, f         


        
3条回答
  •  抹茶落季
    2021-02-02 11:02

    1. The directory option is a prefix for your entire path.
    2. Relative paths are not working correctly in later versions of Restify (I tested 2.6.0-3, 2.8.2-3 - and they all produce the NotAuthorized error)

    The solution now becomes:

    server.get(/\/docs\/public\/?.*/, restify.serveStatic({
        directory: __dirname
    }));
    

    And then your static files will need to be in ./docs/public.
    (__dirname is a global variable that contains the absolute path of the script you are running)

提交回复
热议问题