So I am trying to implement CRUD into my Backbone app by using the book from Addy Osmani. 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. 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. 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.
The general problem i was having was the setup with the Express app server. The line that caused the trouble was
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
the page that you actually want to visit (like your index.html or static.html) can be found under
without any /myApplication following the localhost. This also helps with the general url settings in the app itself as it really just needs to be /api/myModels