【发布时间】:2015-05-12 14:34:28
【问题描述】:
我有一个 server 和 client 文件夹,在我的客户端文件夹中我有 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);
在我的仪表板应用程序中,我的帐户控制器有以下 $resource 调用:
var Account = $resource('/api/accounts');
假设在我的服务器 main.js 上命中此 API:
// API to add new accounts:
app.post('/api/accounts/', accountsController.create);
但目前在通话中遇到 404
'POST http://localhost:9999/api/accounts 404(未找到)'
【问题讨论】:
-
也许是斜线不匹配的问题?试试
app.post('/api/accounts', accountsController.create); -
@PeterLyons 谢谢!你想继续发布答案吗?不知道尾随/匹配在这里会那么严格
标签: angularjs node.js api express ngresource