خرید بک لینک

Vote count: 0

I've been scratching my head for two days on this and it makes no sense to me!

I'm trying to do a very simple operation using two servers ruing on my local machine. API is on port 5000 and front-end (react) is requesting from 8080.

ROUTER

router.post('/api/entry', function(req, res) {
    parserEntry(req.body, function(err, res1){
        if(err)
            throw(err);

        res.json({response:'YES!!' }); //I'll have res1 data here, eventually.
    });
});

parserEntry FUNCTION

exports.entry = function(req, callback){
    if (!req.message) {
        retu new Error("No request!!");
    }
    else {

        Promise.join(
              function1(req.message),
              function2(req.message),
              function (function1, function2) {

                var insert = {
                    a:function1,
                    b:function2
                }

                record_insert(insert, function(err, res){
                    if(err)
                        throw(err)
                    callback(null, res);
                });

              }
            )

    }
}

rectod_insert FUNCTION

exports.record_insert = function(req, callback){
    mongoose.model('Record').create({
        uid : 1,
        a : req.a,
        b: req.b
    }, function (err, res) {
          if (err)
              throw (err);

          retu callback(null, res);
    });
}

APP

var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:8080');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Credentials','true');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header('Content-Type', 'application/json');
    next();
}

var app = express();

app.set('port', process.env.PORT || 5000);
app.set('views', __diame + '/views');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(allowCrossDomain);
app.use(express.static(path.join(__diame, 'public')));


app.use('/', routes);

I'm expecting a respond in the router but instead I get

POST http://127.0.0.1:5000/api/entry net::ERR_EMPTY_RESPONSE

Uncaught Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.Request.crossDomainError @ client.js:814xhr.onreadystatechange

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 26 ارديبهشت 1395 ساعت: 8:30

صفحه بندی