使用Hapi v17,我只是想制作一个简单的Web API来开始构建我的知识,但每次测试构建的GET方法时都会收到错误。下面是我运行的代码:TypeError:回复不是函数
'use strict';
const Hapi = require('hapi');
const MySQL = require('mysql');
//create a serve with a host and port
const server = new Hapi.Server({
host: 'serverName',
port: 8000
});
const connection = MySQL.createConnection({
host: 'host',
user: 'root',
password: 'pass',
database: 'db'
});
connection.connect();
//add the route
server.route({
method: 'GET',
path: '/helloworld',
handler: function (request, reply) {
return reply('hello world');
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
下面是我收到的错误:我不清楚,为什么有呼叫应答功能的问题
Debug: internal, implementation, error
TypeError: reply is not a function
at handler (/var/nodeRestful/server.js:26:11)
,但它是一个致命的现在的错误。
'console.log(reply)'输出的是什么? – 3Dos
@ 3Dos它打印以下内容:“{”statusCode“:500,”error“:”内部服务器错误“,”消息“:”发生内部服务器错误“} – Drew
@MikaelLennholm间距刚好是一条线我相信。错误发生在'return reply('hello world');' – Drew