angularjs - 在 MEAN 应用程序的 API 路由上找不到 404?

标签 angularjs node.js http-post http-status-code-404

在我的应用程序中,当提交其中一个表单时,会调用此函数...

$scope.submit = function() {
    $scope.message = "";
    var params = {
        ...
    };
    Subscriber.create(params)
        .success(function(data) {
            ...
        });
};

这又调用此 subFactory 创建方法,该方法将消息发送到“/mail”。

subFactory.create = function(subData) {
    return $http.post('/mail', subData);
};

在尝试发布到“/mail”时,我收到此错误POST http://localhost:8080/mail 404(未找到)。我不知道如何解决,因为我有这个......

apiRouter.route('/mail')
    .post(function(req, res) {
        ...
    });

据我所知,我应该能够找到“/mail”。完整的 apiRouter 位于 here ,完整的 server.js 文件位于 here .

最佳答案

当您在 server.js 中设置 api 路由时,您将其路由到 /api,因此添加到路由器的所有路由都将从这里开始。因此,您的 /mail 路由位于 /api/mail

server.js

// ROUTES
// ========

// API ROUTE
// -------------
var apiRoutes = require('./app/routes/api')(app, express);
app.use('/api', apiRoutes);

./app/routes/api

apiRouter.route('/mail')
    .post(function(req, res) {

关于angularjs - 在 MEAN 应用程序的 API 路由上找不到 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29547176/

相关文章:

javascript - HTML5 pushState Clash w/Angular UI-Router URL 路由

javascript - 如何从其他 Controller 关闭 Angular-ui 模式

javascript - angularjs 记住我的功能

node.js - fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory in production

javascript - map() 与 async 与 promise.all()

java - 套接字:简单的 POST 请求不起作用

http - 如何使用 Matlab 或 Octave 进行 HTTP GET 或 POST?

javascript - ng-change 不触发

node.js - npm "UNMET PEER DEPENDENCY"如何解决

python - 在 python 中使用 AWS Lambda 将 Post 请求发送到外部 API