我正在使用以下脚本,但此脚本引发错误,即serveStatic不是函数
我已经使用此命令“npm install --save restify”安装了restify。

var restify = require('restify');
var builder = require('botbuilder');

var server = restify.createServer();

server.listen(process.env.port || process.env.PORT || 3978, function () { });



// Create the chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: '***',
    appPassword: '***'
});

// Listen for messages from users
server.post('/api/messages', connector.listen());

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


var bot = new builder.UniversalBot(connector, function (session) {
    var msg = session.message;
    if (msg.attachments && msg.attachments.length > 0) {
     // Echo back attachment
     var attachment = msg.attachments[0];
        session.send({
            text: "You sent:",
            attachments: [
                {
                    contentType: attachment.contentType,
                    contentUrl: attachment.contentUrl,
                    name: attachment.name
                }
            ]
        });
    } else {
        // Echo back users text
        session.send("You said: %s", session.message.text);
    }
});

上面的代码在执行时抛出此错误
C:\Users\Tushar\botforarticle\app.js:20
server.get('/', restify.serveStatic({
                        ^

TypeError: restify.serveStatic is not a function
    at Object.<anonymous> (C:\Users\Tushar\botforarticle\app.js:20:25)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

最佳答案

显然,这在v5.0.0(仅在几天前发布)中已更改,但是文档尚未更新。

试试这个:

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

关于node.js - restify.serveStatic不是函数错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44869195/

10-12 06:39