404在“nodejs / health / check”到达Node.js服务器时出错
我在Drupal 7网站上使用了一个nodejs模块。 以下是我在随机页面上login的消息:
消息在“nodejs / health / check”到达Node.js服务器的错误:[404] Not Found。
尝试重新启动Nodejs,但它似乎已经在运行。 那么为什么这个错误?
你如何重新启动你的节点服务器。 从你启动服务器的terminal,你会得到你的堆栈跟踪。 或者如果它返回错误,你可以简单地从你的浏览器屏幕上看到请求发起的地方。
terminal是你在linux和Osx上键入东西的黑屏,类似于窗口的命令提示符。
这是一个获取或发布的请求。 你使用快递吗? 我假设你是。 寻找文件应用程序,js或routes.js你可能有像这样的代码:
var express = require('express'); var router = express.Router();` router.post('/user/', controllers.users.create); //This is a route
你的节点目录中会有一个像app.js的文件
你必须有一个定义如下的路由:
router.<method>('<route>',<function(req, res, next){}> ) ;
所以如果它的get请求,路由是“nodejs / health / check”,以及一些作为你的api端点的函数:你应该有一行:
router.get('nodejs/health/check', checkHealth(req, res){ console.log("output something"); res.send("Outputed Something") } ) ;
哪里
-
路由器是expression对象的实例。
-
checkHealth是函数端点,如上所示,或者在另一个控制器文件中定义。
看来你的路线不存在。 要创build一条路线,您将执行如下操作:
var router = express.Router(); router.get('/nodejs/health/check', function(req, res, next){ res.render('theHTMLPage', {foo:bar}); //in the {}, you will be passing params the html page might need if it using a template engine })
要么
router.get('/nodejs/health/check', function(req, res, next){ res.send('Whatever you want to send back'); })
res.render告诉节点转到这个其他的URL并传递参数res.send只是传递一些信息,如上面例子中的'无论你想要发回'