我有服务器和客户端文件夹,在我的客户端文件夹中我有2个Angular应用/website
和/dashboard
我的当前路由设置(仅用于开发)将加载网站应用和视图,/
加载信息中心:
/dashboard
在我的信息中心应用中,帐户控制器我有以下$资源调用:
//website api ==================================================================
var website = express.Router();
app.use('/', website);
app.use('/', express.static("../client/"));
console.log(__dirname + "../client/");
website.use(function(req, res, next) {
console.log(req.method, req.url);
next();
});
website.get('/', function(req, res) {
var path = 'index.html';
res.sendfile(path, { 'root': '../client/website/' });
});
//dashboard api ================================================================
var dashboard = express.Router();
app.use('/dashboard', dashboard);
dashboard.use(function(req, res, next) {
console.log(req.method, req.url);
next();
});
dashboard.get('/dashboard', function(req, res) {
var path = 'index.html';
res.sendfile(path, { 'root': '../client/dashboard/' });
});
// API to add new accounts:
app.post('/api/accounts/', accountsController.create);
假设在我的服务器main.js上点击此API:
var Account = $resource('/api/accounts');
但目前正在通话中获得404
'POST http://localhost:9999/api/accounts 404(Not Found)'
答案 0 :(得分:2)
我认为你的angularjs代码和你的expressjs代码之间的尾随斜杠与没有尾随斜杠的不匹配。试试app.post('/api/accounts', accountsController.create);
。