我正在关注this tutorial
我有一个文件夹路由,其中有两个子文件夹user和home,每个文件夹包含两个分别命名为index.js的js文件。 但是在运行我的主要server.js文件时,出现此错误:-
错误 测试 C:\ Users \ user \ Desktop \ social_network \ node_modules \ hapi \ node_modules \ hoek \ lib \ index.js:737 抛出新的错误(msgs.join('')||'未知错误'); ^
Error: Route missing path
at Object.exports.assert (C:\Users\user\Desktop\social_network\node_modules\hapi\node_modules\hoek\lib\index.js:737:11)
at new module.exports.internals.Route (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\route.js:40:10)
at module.exports.internals.Connection.internals.Connection._addRoute (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\connection.js:387:19)
at module.exports.internals.Connection.internals.Connection._route (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\connection.js:379:18)
at module.exports.internals.Plugin.internals.Plugin._apply (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\plugin.js:572:14)
at module.exports.internals.Plugin.internals.Plugin.route (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\plugin.js:542:10)
at Object.module.exports.register (C:\Users\user\Desktop\social_network\routes\home\index.js:3:12)
at Object.target [as register] (C:\Users\user\Desktop\social_network\node_modules\hapi\node_modules\joi\lib\object.js:79:30)
at each (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\plugin.js:317:14)
at iterate (C:\Users\user\Desktop\social_network\node_modules\hapi\node_modules\items\lib\index.js:36:13)
at Object.exports.serial (C:\Users\user\Desktop\social_network\node_modules\hapi\node_modules\items\lib\index.js:39:9)
at module.exports.internals.Server.internals.Plugin.register (C:\Users\user\Desktop\social_network\node_modules\hapi\lib\plugin.js:320:11)
at Object.<anonymous> (C:\Users\user\Desktop\social_network\server.js:73:8)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
家庭用户的路由似乎有问题,因为用户文件正常工作,因为当我不注释该部分server.register时,它显示错误 这是我的server.js文件代码:-
const Hapi=require("hapi");
const server=new Hapi.Server();
server.connection({port:2000});
server.start(console.log("test"));
const mongoose = require("mongoose");
const node_connect_db=mongoose.connect("mongodb://test:test456@ds149034.mlab.com:49034/node_connect1");
const User=require("./database_models/user_model");
server.route({
method:"GET",
path:"/",
handler:function(request,reply){
reply.view("landing.ejs");
}
})
server.register(require("vision"),function(err){
server.views({
engines:{
ejs:require("ejs")
},
relativeTo:__dirname,
path:"views"
})
});
server.register(require("inert"),function(err){
});
server.register(require("hapi-auth-cookie"));
server.auth.strategy("simple-cookie-strategy","cookie",{
cookie:"node_connect_cookie",
password:"abcdefghabcdefghabcdefghabcdefgh",
isSecure:false
})
server.register({
register:require("./routes/users")
},function(err)
{ if(err){
return;
}
});
server.register({
register:require("./routes/home")
},function(err)
{ if(err){
return;
}
});
server.route({
method:"GET",
path:"/{param*}",
handler:{
directory:{
path:"public"
}
}
})
>Also this is my home/index.js code:-
module.exports.register = function(plugin,options,next){
plugin.route([
{
method:"GET",
url:"/home",
hander:function(request,reply){
console.log("HIII");
reply("home");
}
}
])
next();
}
module.exports.register.attributes = {
pkg:require("./package.json")
};