错误404节点Js heroku应用程序

时间:2017-06-11 03:33:26

标签: javascript node.js heroku socket.io

我正在尝试复制一个示例,只需更改ng-model名称,然后使用url将客户端与服务器进行通信,但会显示该错误。

错误

POST https://nuevohorario.herokuapp.com/enviarAsignatura 404 (Not Found)

Possibly unhandled rejection: {"data":"<h1>Not Found</h1>\n<h2></h2>\n<pre></pre>\n","status":404,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/enviarAsignatura","data":{"data":"calculo"},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"Not Found"}

客户 - &gt;前端

.controller('ctrl-asignatura',function($scope,sk,$http){

                        $scope.date= new Date();
                        $scope.data=[];
                        var vector = [];
                        $scope.m=function(){

                            $http.post('/enviar', {data : $scope.asignatura}).then(function(response){
                                console.log(response);
                            })

                        }

                       sk.on('registrar',function(s){
                            alert(s);
                        });

后端 - &gt;节点Js - Socket.IO

var express = require('express');
var router = express.Router();
var misocket = require('../routes/misocket');

/* GET users listing. */
router.post('/enviar', function(req, res, next) {

    console.log(misocket);

    misocket.emit("registrar",req.body);
    console.log(req.body);
    res.status(200).json({
        message  : "send message"
    });

});

module.exports = router;

misocket.js

var i =0;
var ioapp;
exports.connection= function(io){

    ioapp=io;

    io.on('connect',function(s){
        console.log("conetado");   
    })

}

exports.io=ioapp;

index.js

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;

1 个答案:

答案 0 :(得分:0)

您似乎正在使用路由器级中间件

var router = express.Router()

尝试使用router.use()函数加载路由器级中间件。

router.use('/enviarAsignatura', function(req, res, next) {
     //your code here
}