使用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