时间:2017-06-30 13:04:11

标签: javascript node.js routing restify

当用户输入路线' /'时,我试图提供静态文件。

server.get(/\/?.*/, [restify.serveStatic({ directory: 'public/', default: 'index.html'}), exampleFunction])

所以我的目标是服务器静态文件(它可以工作),然后运行一个名为 exampleFunction的函数。

我怎样才能实现这一目标?现在只调用了serveStatic,之后我没有找到运行exampleFunction的方法。

2 个答案:

答案 0 :(得分:0)

不要知道你正在使用哪些框架等,但我猜......

您无法将数组传递给server.get,但您可以将自己的函数传递给

server.get(/\/?.*/, function(req, res){
    restify.serveStatic({ directory: 'public/', default: 'index.html'});
    customFunction();
})

答案 1 :(得分:-1)

它已更新为

server.get(
  "/",
  restify.plugins.serveStatic({
    directory: __dirname + "/frontend/assets",
    default: "frontend/index.html",
  })
);