我正在尝试复制一个示例,只需更改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"}
.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);
});
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;
var i =0;
var ioapp;
exports.connection= function(io){
ioapp=io;
io.on('connect',function(s){
console.log("conetado");
})
}
exports.io=ioapp;
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;
答案 0 :(得分:0)
您似乎正在使用路由器级中间件
var router = express.Router()
尝试使用router.use()函数加载路由器级中间件。
router.use('/enviarAsignatura', function(req, res, next) {
//your code here
}