404 error in node application js in heroku

2

I'm trying to replicate an example to receive some data in real time to emulate adding a subject, but no matter how much you upload and / or change the form, that error still exists.

Error

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"}

Client - Angular and Socket.IO

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

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

                            //$scope.data.push($scope.informacion);
                            //console.log(vector)

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

                        }

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

Server - Node Js and Socket.IO

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

/* GET users listing. */
router.post('/enviarAsignatura', 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;
    
asked by Pedro Miguel Pimienta Morales 11.06.2017 в 05:21
source

1 answer

0

You are creating bad connections. For example for http you have to do the following:

var app = express (); var server = require ('http'). Server (app); var io = require ('socket.io') (server);

As you can see, websockets are sent under the http server. For https it will be the same but also adding the certificates I suppose. Luck! :)

    
answered by 01.07.2017 в 20:48