i getting 404 response after sending following request. have tried different api names still getting same error.
backend: node+express+mongoose frontend: angularjs
frontend code (angularjs)
$http.post('http://0.0.0.0:8000/users/supervisors', function(response) { console.log(response); });
backend code (mongoose+mongodb)
// express import var express = require('express'); // mongoose import var mongoose = require('mongoose'); // mongoose connection mongodb (database: dummydatabase readonly) mongoose.connect('mongodb://0.0.0.0/dummydatabase', function (error) { if (error) { console.log(error); } }); // mongoose schema definition var schema = mongoose.schema; var userschema = new schema({ name: string, location: string, parentid: number }); // mongoose model definition var user = mongoose.model('users', userschema); // bootstrap express var app = express(); // add headers app.use(function (req, res, next) { // website wish allow connect res.setheader('access-control-allow-origin', '*'); // request methods wish allow res.setheader('access-control-allow-methods', 'get, post, options, put, delete'); // request headers wish allow res.setheader('access-control-allow-headers', 'x-requested-with,content-type'); // set true if need website include cookies in requests sent // api (e.g. in case use sessions) res.setheader('access-control-allow-credentials', true); // pass next layer of middleware next(); }); app.get('/users/supervisors', function (req, res, next) { user.find({}, function (err, docs) { res.send(docs); }); });
Comments
Post a Comment