[英]Backbone RESTful CRUD 404
So I am trying to implement CRUD into my Backbone app by using the book from Addy Osmani . 因此,我尝试使用Addy Osmani的书将CRUD实施到我的Backbone应用程序中。 One of the problems that I encounter is, that although I am currently using the same code for the NodeJS server with express/mongoose/path I get 404 for all CRUD operations.
我遇到的问题之一是,尽管我目前对带有Express / Mongoose / path的NodeJS服务器使用相同的代码,但我得到的所有CRUD操作都为404。 Here is my currently folder structure on localhost
这是我当前在本地主机上的文件夹结构
/
/myApplication/ (working dir)
/myApplication/js (contains all js files from Backbone app)
/myApplication/mongoServer.js (the server app)
So according to the guide the only thing that has to be set is the url in the collection 因此,根据指南,唯一需要设置的是集合中的网址
myCollection = Backbone.Collection.extend({
model: myModel,
url: '/api/myModels'
...
})
What I would expect is, that once I add a model, as it is part of the collection, it creates a collection (if it did not exist) and then syncs it with the server. 我期望的是,一旦添加了模型(因为它是集合的一部分),它就会创建一个集合(如果不存在),然后将其与服务器同步。 This probably happens, BUT with one exception
可能发生这种情况,但有一个例外
POST http://localhost/api/todos 404 (Not Found)
Of course I see that thats not correct as it probably needs to look at the path 当然,我认为那是不正确的,因为它可能需要查看路径
POST http://localhost/myApplication/api/todos
because the mongoServer.js is in the folder of myApplication. 因为mongoServer.js位于myApplication的文件夹中。 I do not really know how to solve this problem.
我真的不知道如何解决这个问题。 Maybe one could change routes or maybe there is a flaw in my logic about my implementation?
也许有人可以改变路线,或者我的实现逻辑存在缺陷?
Edit: Also to clarify, i've already tested 编辑:还要澄清一下,我已经测试过
url: '/myApplication/api/myModels'
the XHR finishes loading, but the POST is still 404. XHR完成加载,但POST仍为404。
The general problem i was having was the setup with the Express app server. 我遇到的一般问题是Express应用服务器的设置。 The line that caused the trouble was
造成麻烦的那条线是
app.configure(function() {
app.use(express.static(path.join(application_root, "public")));
});
Which basically tells express that the static path to the app is in the public folder (which i did not have apparently). 从根本上讲,这表明该应用程序的静态路径在公用文件夹中(我显然没有)。 As the express server listens to the port you choose via
当快递服务器监听您通过选择的端口时
app.listen(3000);
the page that you actually want to visit (like your index.html or static.html) can be found under 您实际要访问的页面(例如index.html或static.html)可以在下面找到
http://localhost:3000/index.html or static.html
without any /myApplication following the localhost. 在本地主机之后没有任何/ myApplication 。 This also helps with the general url settings in the app itself as it really just needs to be /api/myModels
这也有助于应用本身中的常规url设置,因为它实际上只需要是/ api / myModels
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.