restify.serveStatic 不是函数错误
restify.serveStatic is not a function error
我正在使用以下脚本,但此脚本抛出 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'
}));
我正在使用以下脚本,但此脚本抛出 serveStatic 不是函数的错误 我已经使用此命令 "npm install --save restify"
安装了 restifyvar 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'
}));