Angular to Node + Express.js http.post() stalled: status 204 no content. Suspected CORS Preflight OPTIONS












-1















I'm using client side ionic with server side node.js + express.js. Currently testing in my local computer.



I am able to do a POST request through postman, however I couldn't make it through ionic.



Research



I have spent almost 1 day to investigate this. But I couldn't find a way to solve this. More over, there is no error on the client nor the server side, thus it is difficult for me to investigate this.



From what I can see, I suspect the error comes from the PREFLIGHT OPTIONS settings. I should set it somewhere in my node + express.
I am using the cors plugin https://www.npmjs.com/package/cors and use the settings to allow PREFLIGHT OPTIONS, however it still does not work.



I looked at the chrome network inspection, this is what I have:
Network Inspection (1)Network Inspection (2)



And this is what it looks in the console.
Console Inspection



My Client-side Code (Ionic)



postAPI() {
return new Promise ((resolve,reject)=>{
this.http.post("http://localhost:8080/api/status/", {
"body" : "This is the body post"
}, httpOptions).subscribe((val) => {
console.log("POST call successful value returned in body", val);
resolve();
}, error => {
console.log("POST call in error", error);
reject();
}, () => {
console.log("The POST observable is now completed.");
})
})
}


My Server-side Code (Node + Express)



Here, I am using CORS OPTIONS settings to allow all OPTIONS requests.
I am setting it in server.js while the route itself is in status.js.



server.js



const express    = require('express');           // call express
const app = express(); // define our app using express
var cors = require('cors'); // setup CORS so can be called by ionic local app
const port = process.env.PORT || 8080; // set our port

// ALLOW CORS
app.use(cors());
// SET CORS for PREFLIGHT OPTIONS
app.options('*', cors());

// Libraries
const bodyParser = require('body-parser');

const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');

// Json
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// Firebase Configs
//firebase admin sdk for Firestore
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://menuu-sm-dev.firebaseio.com"
});

var afs = admin.firestore();
var db = afs;
app.set("afs", afs);
var db = admin.firestore();
const settings = {timestampsInSnapshots: true};
db.settings(settings);

app.set("db", db);

// ROUTES
app.use('/api',require('./routers/api/api'));
app.use('/',require('./routers/home'));

// START
app.listen(port);
console.log('Server is served on port ' + port);


api.js



// SETUP
const express = require('express'),
router = express.Router();
const url = require("url");
const path = require("path");
///const sanitizer = require("sanitize")();

// ROUTES (/api/)
router.use('/user',require('./user'));
router.use('/status',require('./status'));
router.use('/timeline',require('./timeline'));
router.use('/photo',require('./photo'));
router.use('/like',require('./like'));
router.use('/comment',require('./comment'));
router.use('/checkin',require('./checkin'));
router.use('/promotion',require('./promotion'));

// OTHERS
module.exports = router;


status.js



// SETUP
const express = require('express'),
router = express.Router();
const url = require("url");
const path = require("path");
const Timeline = require("../../models/Timeline");
const Post = require("../../models/Post");
///const sanitizer = require("sanitize")();

// ROUTES

// ===============================================================
// /status/
var statusRoute = router.route('');

// Create
statusRoute.post((req, res) => {
let query = url.parse(req.url,true).query;
let userKey = query.userkey;
let statusKey = query.statuskey; // ga dipake
let reqBody = req.body;
let db = req.app.get('db');
// ! remember to do sanitizing here later on

if (typeof userKey != 'undefined'){
// Create New Status
let newStatusRef = db.collection('status/'+userKey+'/status').doc();
newStatusRef.set(reqBody);

// Fan-Out
let docId = newStatusRef.id; // get pushed id
//let docId = "1";

// Insert request body to models
var post = new Post();
var timeline = new Timeline();
Object.entries(reqBody).forEach( ([key, value]) => {
timeline.set(key,value);
post.set(key,value);
}
);

// Specify operations to be done
var batch = db.batch();
let newPostRef = db.collection('posts/'+userKey+'/posts').doc(docId);
batch.set(newPostRef, post.data);
console.log("b" + batch);


// Timeline & Commit
getFollowers(userKey, db)
.catch((error) => {
console.error("Error writing document: ", error)
})
.then((followers) => {
// ATTENTION!!
// if followers > 9, batch write supposedly wont work because max limit of batch write is 10
if (followers.length!=0){
followers.forEach((f) => {
let newTimelineRef = db.collection('timeline/'+String(f)+'/timeline').doc(docId);
console.log(typeof batch);
console.log("a" + batch);
batch.set(newTimelineRef, timeline.data);
});
}

// Commit changes
batch.commit()
.then(() => {
console.log("POST Request");
res.json({"Action":"CREATE","Status":"Successful", "User key":userKey, "Post Key": docId, "followers":followers});
})
.catch((error) => {
console.error("Error writing document: ", error)
})
});
}
});


Could you help me find the cause of this issue. Thanks!










share|improve this question





























    -1















    I'm using client side ionic with server side node.js + express.js. Currently testing in my local computer.



    I am able to do a POST request through postman, however I couldn't make it through ionic.



    Research



    I have spent almost 1 day to investigate this. But I couldn't find a way to solve this. More over, there is no error on the client nor the server side, thus it is difficult for me to investigate this.



    From what I can see, I suspect the error comes from the PREFLIGHT OPTIONS settings. I should set it somewhere in my node + express.
    I am using the cors plugin https://www.npmjs.com/package/cors and use the settings to allow PREFLIGHT OPTIONS, however it still does not work.



    I looked at the chrome network inspection, this is what I have:
    Network Inspection (1)Network Inspection (2)



    And this is what it looks in the console.
    Console Inspection



    My Client-side Code (Ionic)



    postAPI() {
    return new Promise ((resolve,reject)=>{
    this.http.post("http://localhost:8080/api/status/", {
    "body" : "This is the body post"
    }, httpOptions).subscribe((val) => {
    console.log("POST call successful value returned in body", val);
    resolve();
    }, error => {
    console.log("POST call in error", error);
    reject();
    }, () => {
    console.log("The POST observable is now completed.");
    })
    })
    }


    My Server-side Code (Node + Express)



    Here, I am using CORS OPTIONS settings to allow all OPTIONS requests.
    I am setting it in server.js while the route itself is in status.js.



    server.js



    const express    = require('express');           // call express
    const app = express(); // define our app using express
    var cors = require('cors'); // setup CORS so can be called by ionic local app
    const port = process.env.PORT || 8080; // set our port

    // ALLOW CORS
    app.use(cors());
    // SET CORS for PREFLIGHT OPTIONS
    app.options('*', cors());

    // Libraries
    const bodyParser = require('body-parser');

    const admin = require('firebase-admin');
    const serviceAccount = require('./serviceAccountKey.json');

    // Json
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());

    // Firebase Configs
    //firebase admin sdk for Firestore
    admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://menuu-sm-dev.firebaseio.com"
    });

    var afs = admin.firestore();
    var db = afs;
    app.set("afs", afs);
    var db = admin.firestore();
    const settings = {timestampsInSnapshots: true};
    db.settings(settings);

    app.set("db", db);

    // ROUTES
    app.use('/api',require('./routers/api/api'));
    app.use('/',require('./routers/home'));

    // START
    app.listen(port);
    console.log('Server is served on port ' + port);


    api.js



    // SETUP
    const express = require('express'),
    router = express.Router();
    const url = require("url");
    const path = require("path");
    ///const sanitizer = require("sanitize")();

    // ROUTES (/api/)
    router.use('/user',require('./user'));
    router.use('/status',require('./status'));
    router.use('/timeline',require('./timeline'));
    router.use('/photo',require('./photo'));
    router.use('/like',require('./like'));
    router.use('/comment',require('./comment'));
    router.use('/checkin',require('./checkin'));
    router.use('/promotion',require('./promotion'));

    // OTHERS
    module.exports = router;


    status.js



    // SETUP
    const express = require('express'),
    router = express.Router();
    const url = require("url");
    const path = require("path");
    const Timeline = require("../../models/Timeline");
    const Post = require("../../models/Post");
    ///const sanitizer = require("sanitize")();

    // ROUTES

    // ===============================================================
    // /status/
    var statusRoute = router.route('');

    // Create
    statusRoute.post((req, res) => {
    let query = url.parse(req.url,true).query;
    let userKey = query.userkey;
    let statusKey = query.statuskey; // ga dipake
    let reqBody = req.body;
    let db = req.app.get('db');
    // ! remember to do sanitizing here later on

    if (typeof userKey != 'undefined'){
    // Create New Status
    let newStatusRef = db.collection('status/'+userKey+'/status').doc();
    newStatusRef.set(reqBody);

    // Fan-Out
    let docId = newStatusRef.id; // get pushed id
    //let docId = "1";

    // Insert request body to models
    var post = new Post();
    var timeline = new Timeline();
    Object.entries(reqBody).forEach( ([key, value]) => {
    timeline.set(key,value);
    post.set(key,value);
    }
    );

    // Specify operations to be done
    var batch = db.batch();
    let newPostRef = db.collection('posts/'+userKey+'/posts').doc(docId);
    batch.set(newPostRef, post.data);
    console.log("b" + batch);


    // Timeline & Commit
    getFollowers(userKey, db)
    .catch((error) => {
    console.error("Error writing document: ", error)
    })
    .then((followers) => {
    // ATTENTION!!
    // if followers > 9, batch write supposedly wont work because max limit of batch write is 10
    if (followers.length!=0){
    followers.forEach((f) => {
    let newTimelineRef = db.collection('timeline/'+String(f)+'/timeline').doc(docId);
    console.log(typeof batch);
    console.log("a" + batch);
    batch.set(newTimelineRef, timeline.data);
    });
    }

    // Commit changes
    batch.commit()
    .then(() => {
    console.log("POST Request");
    res.json({"Action":"CREATE","Status":"Successful", "User key":userKey, "Post Key": docId, "followers":followers});
    })
    .catch((error) => {
    console.error("Error writing document: ", error)
    })
    });
    }
    });


    Could you help me find the cause of this issue. Thanks!










    share|improve this question



























      -1












      -1








      -1








      I'm using client side ionic with server side node.js + express.js. Currently testing in my local computer.



      I am able to do a POST request through postman, however I couldn't make it through ionic.



      Research



      I have spent almost 1 day to investigate this. But I couldn't find a way to solve this. More over, there is no error on the client nor the server side, thus it is difficult for me to investigate this.



      From what I can see, I suspect the error comes from the PREFLIGHT OPTIONS settings. I should set it somewhere in my node + express.
      I am using the cors plugin https://www.npmjs.com/package/cors and use the settings to allow PREFLIGHT OPTIONS, however it still does not work.



      I looked at the chrome network inspection, this is what I have:
      Network Inspection (1)Network Inspection (2)



      And this is what it looks in the console.
      Console Inspection



      My Client-side Code (Ionic)



      postAPI() {
      return new Promise ((resolve,reject)=>{
      this.http.post("http://localhost:8080/api/status/", {
      "body" : "This is the body post"
      }, httpOptions).subscribe((val) => {
      console.log("POST call successful value returned in body", val);
      resolve();
      }, error => {
      console.log("POST call in error", error);
      reject();
      }, () => {
      console.log("The POST observable is now completed.");
      })
      })
      }


      My Server-side Code (Node + Express)



      Here, I am using CORS OPTIONS settings to allow all OPTIONS requests.
      I am setting it in server.js while the route itself is in status.js.



      server.js



      const express    = require('express');           // call express
      const app = express(); // define our app using express
      var cors = require('cors'); // setup CORS so can be called by ionic local app
      const port = process.env.PORT || 8080; // set our port

      // ALLOW CORS
      app.use(cors());
      // SET CORS for PREFLIGHT OPTIONS
      app.options('*', cors());

      // Libraries
      const bodyParser = require('body-parser');

      const admin = require('firebase-admin');
      const serviceAccount = require('./serviceAccountKey.json');

      // Json
      app.use(bodyParser.urlencoded({ extended: true }));
      app.use(bodyParser.json());

      // Firebase Configs
      //firebase admin sdk for Firestore
      admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "https://menuu-sm-dev.firebaseio.com"
      });

      var afs = admin.firestore();
      var db = afs;
      app.set("afs", afs);
      var db = admin.firestore();
      const settings = {timestampsInSnapshots: true};
      db.settings(settings);

      app.set("db", db);

      // ROUTES
      app.use('/api',require('./routers/api/api'));
      app.use('/',require('./routers/home'));

      // START
      app.listen(port);
      console.log('Server is served on port ' + port);


      api.js



      // SETUP
      const express = require('express'),
      router = express.Router();
      const url = require("url");
      const path = require("path");
      ///const sanitizer = require("sanitize")();

      // ROUTES (/api/)
      router.use('/user',require('./user'));
      router.use('/status',require('./status'));
      router.use('/timeline',require('./timeline'));
      router.use('/photo',require('./photo'));
      router.use('/like',require('./like'));
      router.use('/comment',require('./comment'));
      router.use('/checkin',require('./checkin'));
      router.use('/promotion',require('./promotion'));

      // OTHERS
      module.exports = router;


      status.js



      // SETUP
      const express = require('express'),
      router = express.Router();
      const url = require("url");
      const path = require("path");
      const Timeline = require("../../models/Timeline");
      const Post = require("../../models/Post");
      ///const sanitizer = require("sanitize")();

      // ROUTES

      // ===============================================================
      // /status/
      var statusRoute = router.route('');

      // Create
      statusRoute.post((req, res) => {
      let query = url.parse(req.url,true).query;
      let userKey = query.userkey;
      let statusKey = query.statuskey; // ga dipake
      let reqBody = req.body;
      let db = req.app.get('db');
      // ! remember to do sanitizing here later on

      if (typeof userKey != 'undefined'){
      // Create New Status
      let newStatusRef = db.collection('status/'+userKey+'/status').doc();
      newStatusRef.set(reqBody);

      // Fan-Out
      let docId = newStatusRef.id; // get pushed id
      //let docId = "1";

      // Insert request body to models
      var post = new Post();
      var timeline = new Timeline();
      Object.entries(reqBody).forEach( ([key, value]) => {
      timeline.set(key,value);
      post.set(key,value);
      }
      );

      // Specify operations to be done
      var batch = db.batch();
      let newPostRef = db.collection('posts/'+userKey+'/posts').doc(docId);
      batch.set(newPostRef, post.data);
      console.log("b" + batch);


      // Timeline & Commit
      getFollowers(userKey, db)
      .catch((error) => {
      console.error("Error writing document: ", error)
      })
      .then((followers) => {
      // ATTENTION!!
      // if followers > 9, batch write supposedly wont work because max limit of batch write is 10
      if (followers.length!=0){
      followers.forEach((f) => {
      let newTimelineRef = db.collection('timeline/'+String(f)+'/timeline').doc(docId);
      console.log(typeof batch);
      console.log("a" + batch);
      batch.set(newTimelineRef, timeline.data);
      });
      }

      // Commit changes
      batch.commit()
      .then(() => {
      console.log("POST Request");
      res.json({"Action":"CREATE","Status":"Successful", "User key":userKey, "Post Key": docId, "followers":followers});
      })
      .catch((error) => {
      console.error("Error writing document: ", error)
      })
      });
      }
      });


      Could you help me find the cause of this issue. Thanks!










      share|improve this question
















      I'm using client side ionic with server side node.js + express.js. Currently testing in my local computer.



      I am able to do a POST request through postman, however I couldn't make it through ionic.



      Research



      I have spent almost 1 day to investigate this. But I couldn't find a way to solve this. More over, there is no error on the client nor the server side, thus it is difficult for me to investigate this.



      From what I can see, I suspect the error comes from the PREFLIGHT OPTIONS settings. I should set it somewhere in my node + express.
      I am using the cors plugin https://www.npmjs.com/package/cors and use the settings to allow PREFLIGHT OPTIONS, however it still does not work.



      I looked at the chrome network inspection, this is what I have:
      Network Inspection (1)Network Inspection (2)



      And this is what it looks in the console.
      Console Inspection



      My Client-side Code (Ionic)



      postAPI() {
      return new Promise ((resolve,reject)=>{
      this.http.post("http://localhost:8080/api/status/", {
      "body" : "This is the body post"
      }, httpOptions).subscribe((val) => {
      console.log("POST call successful value returned in body", val);
      resolve();
      }, error => {
      console.log("POST call in error", error);
      reject();
      }, () => {
      console.log("The POST observable is now completed.");
      })
      })
      }


      My Server-side Code (Node + Express)



      Here, I am using CORS OPTIONS settings to allow all OPTIONS requests.
      I am setting it in server.js while the route itself is in status.js.



      server.js



      const express    = require('express');           // call express
      const app = express(); // define our app using express
      var cors = require('cors'); // setup CORS so can be called by ionic local app
      const port = process.env.PORT || 8080; // set our port

      // ALLOW CORS
      app.use(cors());
      // SET CORS for PREFLIGHT OPTIONS
      app.options('*', cors());

      // Libraries
      const bodyParser = require('body-parser');

      const admin = require('firebase-admin');
      const serviceAccount = require('./serviceAccountKey.json');

      // Json
      app.use(bodyParser.urlencoded({ extended: true }));
      app.use(bodyParser.json());

      // Firebase Configs
      //firebase admin sdk for Firestore
      admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "https://menuu-sm-dev.firebaseio.com"
      });

      var afs = admin.firestore();
      var db = afs;
      app.set("afs", afs);
      var db = admin.firestore();
      const settings = {timestampsInSnapshots: true};
      db.settings(settings);

      app.set("db", db);

      // ROUTES
      app.use('/api',require('./routers/api/api'));
      app.use('/',require('./routers/home'));

      // START
      app.listen(port);
      console.log('Server is served on port ' + port);


      api.js



      // SETUP
      const express = require('express'),
      router = express.Router();
      const url = require("url");
      const path = require("path");
      ///const sanitizer = require("sanitize")();

      // ROUTES (/api/)
      router.use('/user',require('./user'));
      router.use('/status',require('./status'));
      router.use('/timeline',require('./timeline'));
      router.use('/photo',require('./photo'));
      router.use('/like',require('./like'));
      router.use('/comment',require('./comment'));
      router.use('/checkin',require('./checkin'));
      router.use('/promotion',require('./promotion'));

      // OTHERS
      module.exports = router;


      status.js



      // SETUP
      const express = require('express'),
      router = express.Router();
      const url = require("url");
      const path = require("path");
      const Timeline = require("../../models/Timeline");
      const Post = require("../../models/Post");
      ///const sanitizer = require("sanitize")();

      // ROUTES

      // ===============================================================
      // /status/
      var statusRoute = router.route('');

      // Create
      statusRoute.post((req, res) => {
      let query = url.parse(req.url,true).query;
      let userKey = query.userkey;
      let statusKey = query.statuskey; // ga dipake
      let reqBody = req.body;
      let db = req.app.get('db');
      // ! remember to do sanitizing here later on

      if (typeof userKey != 'undefined'){
      // Create New Status
      let newStatusRef = db.collection('status/'+userKey+'/status').doc();
      newStatusRef.set(reqBody);

      // Fan-Out
      let docId = newStatusRef.id; // get pushed id
      //let docId = "1";

      // Insert request body to models
      var post = new Post();
      var timeline = new Timeline();
      Object.entries(reqBody).forEach( ([key, value]) => {
      timeline.set(key,value);
      post.set(key,value);
      }
      );

      // Specify operations to be done
      var batch = db.batch();
      let newPostRef = db.collection('posts/'+userKey+'/posts').doc(docId);
      batch.set(newPostRef, post.data);
      console.log("b" + batch);


      // Timeline & Commit
      getFollowers(userKey, db)
      .catch((error) => {
      console.error("Error writing document: ", error)
      })
      .then((followers) => {
      // ATTENTION!!
      // if followers > 9, batch write supposedly wont work because max limit of batch write is 10
      if (followers.length!=0){
      followers.forEach((f) => {
      let newTimelineRef = db.collection('timeline/'+String(f)+'/timeline').doc(docId);
      console.log(typeof batch);
      console.log("a" + batch);
      batch.set(newTimelineRef, timeline.data);
      });
      }

      // Commit changes
      batch.commit()
      .then(() => {
      console.log("POST Request");
      res.json({"Action":"CREATE","Status":"Successful", "User key":userKey, "Post Key": docId, "followers":followers});
      })
      .catch((error) => {
      console.error("Error writing document: ", error)
      })
      });
      }
      });


      Could you help me find the cause of this issue. Thanks!







      node.js angular express ionic-framework cors






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 2:21







      Brian Ivander T. P.

















      asked Jan 3 at 2:14









      Brian Ivander T. P.Brian Ivander T. P.

      7910




      7910
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Replace app.use('cors') with the below code:



          app.use((req, res, next) => {
          res.header("Access-Control-Allow-Origin", '*');
          res.header(
          "Access-Control-Allow-Headers",
          "Origin, X-Requested-With, Content-Type, Accept, Authorization"
          );
          if (req.method === 'OPTIONS') {
          res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
          return res.status(200).json({});
          }
          next();
          });





          share|improve this answer
























          • Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

            – Brian Ivander T. P.
            Jan 3 at 3:47











          • This will only resolve your cors issue, rest you have to see for your functions.

            – Gourav Singla
            Jan 3 at 3:56











          • The function is working when I call it from Postman. I can assure that the function has no problem.

            – Brian Ivander T. P.
            Jan 3 at 4:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015512%2fangular-to-node-express-js-http-post-stalled-status-204-no-content-suspect%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Replace app.use('cors') with the below code:



          app.use((req, res, next) => {
          res.header("Access-Control-Allow-Origin", '*');
          res.header(
          "Access-Control-Allow-Headers",
          "Origin, X-Requested-With, Content-Type, Accept, Authorization"
          );
          if (req.method === 'OPTIONS') {
          res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
          return res.status(200).json({});
          }
          next();
          });





          share|improve this answer
























          • Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

            – Brian Ivander T. P.
            Jan 3 at 3:47











          • This will only resolve your cors issue, rest you have to see for your functions.

            – Gourav Singla
            Jan 3 at 3:56











          • The function is working when I call it from Postman. I can assure that the function has no problem.

            – Brian Ivander T. P.
            Jan 3 at 4:24
















          0














          Replace app.use('cors') with the below code:



          app.use((req, res, next) => {
          res.header("Access-Control-Allow-Origin", '*');
          res.header(
          "Access-Control-Allow-Headers",
          "Origin, X-Requested-With, Content-Type, Accept, Authorization"
          );
          if (req.method === 'OPTIONS') {
          res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
          return res.status(200).json({});
          }
          next();
          });





          share|improve this answer
























          • Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

            – Brian Ivander T. P.
            Jan 3 at 3:47











          • This will only resolve your cors issue, rest you have to see for your functions.

            – Gourav Singla
            Jan 3 at 3:56











          • The function is working when I call it from Postman. I can assure that the function has no problem.

            – Brian Ivander T. P.
            Jan 3 at 4:24














          0












          0








          0







          Replace app.use('cors') with the below code:



          app.use((req, res, next) => {
          res.header("Access-Control-Allow-Origin", '*');
          res.header(
          "Access-Control-Allow-Headers",
          "Origin, X-Requested-With, Content-Type, Accept, Authorization"
          );
          if (req.method === 'OPTIONS') {
          res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
          return res.status(200).json({});
          }
          next();
          });





          share|improve this answer













          Replace app.use('cors') with the below code:



          app.use((req, res, next) => {
          res.header("Access-Control-Allow-Origin", '*');
          res.header(
          "Access-Control-Allow-Headers",
          "Origin, X-Requested-With, Content-Type, Accept, Authorization"
          );
          if (req.method === 'OPTIONS') {
          res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
          return res.status(200).json({});
          }
          next();
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 3:39









          Gourav SinglaGourav Singla

          313




          313













          • Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

            – Brian Ivander T. P.
            Jan 3 at 3:47











          • This will only resolve your cors issue, rest you have to see for your functions.

            – Gourav Singla
            Jan 3 at 3:56











          • The function is working when I call it from Postman. I can assure that the function has no problem.

            – Brian Ivander T. P.
            Jan 3 at 4:24



















          • Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

            – Brian Ivander T. P.
            Jan 3 at 3:47











          • This will only resolve your cors issue, rest you have to see for your functions.

            – Gourav Singla
            Jan 3 at 3:56











          • The function is working when I call it from Postman. I can assure that the function has no problem.

            – Brian Ivander T. P.
            Jan 3 at 4:24

















          Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

          – Brian Ivander T. P.
          Jan 3 at 3:47





          Thanks. Now in Chrome's Network inspection, it returns 200 OK. However it seems it hasn't reached the status.js. The function there which inserts to firestore is not called.

          – Brian Ivander T. P.
          Jan 3 at 3:47













          This will only resolve your cors issue, rest you have to see for your functions.

          – Gourav Singla
          Jan 3 at 3:56





          This will only resolve your cors issue, rest you have to see for your functions.

          – Gourav Singla
          Jan 3 at 3:56













          The function is working when I call it from Postman. I can assure that the function has no problem.

          – Brian Ivander T. P.
          Jan 3 at 4:24





          The function is working when I call it from Postman. I can assure that the function has no problem.

          – Brian Ivander T. P.
          Jan 3 at 4:24




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015512%2fangular-to-node-express-js-http-post-stalled-status-204-no-content-suspect%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas