使用curl --data测试REST路由,返回404 [英] Testing REST routes with curl --data, returns 404

查看:192
本文介绍了使用curl --data测试REST路由,返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个MEAN堆栈教程,我在测试初始路由步骤,其中我们使用cURL测试我们的REST路由。

I am attempting a MEAN stack tutorial and I am at the "Testing the Initial Routes" step, where we test our REST routes using cURL.

我试图运行此命令创建新的帖子:

I am trying to run this command to create a new post:

curl --data 'title=test&link=http://test.com' http://localhost:3000/posts

但是,我不断收到错误。起初错误是:

However, I keep getting errors. At first the error was:

curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
'link' is not recognized as an internal or external command,
operable program or batch file.

然后在一些SO抽烟之后,我发现我需要使用双引号,因为我在Windows。但是,我仍然收到错误:

Then after some SO purusing, I found that I needed to use double quotes since I am on windows. However, I'm still getting an error:

<h1>Not Found</h1>
<h2>404</h2>
<pre>Error: Not Found
at app.use.res.render.message (c:\base\demo\thinkster-mean-tutorial\flapper-news\app.js:30:13)
at Layer.handle [as handle_request] (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\layer.js:82:5)
at trim_prefix (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:302:13)
at c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:321:12)
at next (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:261:10)

at c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:603:15
at next (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:246:14)

at Function.proto.handle (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:166:3)
at router (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:35:12)</pre>

我尝试在教程中运行下一个命令:

I tried running the next command in the tutorial:

curl http://localhost:3000/posts

这导致完全相同的错误。然后我在浏览器中检查了网址,它实际上是: http:// localhost:3000 /#/ posts 。所以我试过运行上面的命令,但使用#url,它返回该页面的html。所以,然后我试图运行初始命令与#url,但我有相同的错误。

This resulted in the exact same error. Then I checked the url in my browser and it is actually: http://localhost:3000/#/posts. So I tried running the above command but with the # url and it returned the html for that page. So then I tried running the initial command with the # url but I got the same error.

不知道接下来要做什么。我遵循教程,甚至回去和复制/粘贴代码,以确保我有它正确,但我仍然得到一个错误。

Not sure what to try next. I followed the tutorial exactly and even went back and copy/pasted code to make sure I had it exactly correct but I'm still getting an error.

推荐答案

原来是我的mongoose模式定义如下module.exports = app;在app.js.所以我只需要移动这些定义上面,它的工作。所以,无论谁提交建议编辑我从这篇文章中删除mongoose标签,非常感谢。 NOT。

So it turns out it my mongoose schema was defined below module.exports = app; in app.js. So I just had to move those definitions above and it worked out. So to whoever submitted suggested edits to me remove the mongoose tag from this post, thanks a lot. NOT.

这篇关于使用curl --data测试REST路由,返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆