Multiple concurrent http requests returning a 400 bad request





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have an angular app in node that uses express to route various different http requests. I first ran into this problem when multiple users tried to upload files using the app at the same time. I first thought this was a problem with global scoped variables that reset the data of overlapping async/await requests.



However, I was able to replicate this problem ("Failed to load resource: the server responded with a status of 400") with a curl to the same port on localhost, which is a default route to a get request. I thought express was supposed to be able to handle multiple http requests? Here is my middleware code in app.js:



const PORT = 9001;
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const routes = require('./routes/routing');

app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
res.header("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE");
next();
});
app.use(bodyParser.json({limit: '20mb', extended: true}))
app.use(bodyParser.urlencoded({limit: '20mb', extended: true}))


routes.appRoutes(app);


app.get('/', function (req, res) {

const example = ;

for (i = 0; i < 1000; i++) {
for (j = 0; j < 1000; j++) {
example.push("test2");
}
example.push("test");
}

res.send(example);
});


app.all('*', function(req, res, next){
res.send('Page not found.');
});

app.listen(PORT, () => {
console.log("App is listening under the port: " + PORT);
});


and here is my routing.js:



const path = require("path");
const multer = require('multer');
const { document } = require('./../controllers');

const diskStorage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, path.resolve("./server/uploads"))
},
filename: function (req, file, callback) {
callback(null, file.originalname + '-' + Date.now() + ".csv")
}
});
const uploadConfig = multer({
storage: diskStorage,
});

const appRoutes = (app) => {
app.post('/upload', uploadConfig.any(), document.upload);
app.post('/process', document.process);
app.get('/getFiles', document.getFiles);
app.get('/getBatches/:fileId', document.getBatches);
};

module.exports = {
appRoutes
}









share|improve this question





























    0















    I have an angular app in node that uses express to route various different http requests. I first ran into this problem when multiple users tried to upload files using the app at the same time. I first thought this was a problem with global scoped variables that reset the data of overlapping async/await requests.



    However, I was able to replicate this problem ("Failed to load resource: the server responded with a status of 400") with a curl to the same port on localhost, which is a default route to a get request. I thought express was supposed to be able to handle multiple http requests? Here is my middleware code in app.js:



    const PORT = 9001;
    const express = require("express");
    const bodyParser = require("body-parser");
    const app = express();
    const routes = require('./routes/routing');

    app.use((req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "*");
    res.header("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE");
    next();
    });
    app.use(bodyParser.json({limit: '20mb', extended: true}))
    app.use(bodyParser.urlencoded({limit: '20mb', extended: true}))


    routes.appRoutes(app);


    app.get('/', function (req, res) {

    const example = ;

    for (i = 0; i < 1000; i++) {
    for (j = 0; j < 1000; j++) {
    example.push("test2");
    }
    example.push("test");
    }

    res.send(example);
    });


    app.all('*', function(req, res, next){
    res.send('Page not found.');
    });

    app.listen(PORT, () => {
    console.log("App is listening under the port: " + PORT);
    });


    and here is my routing.js:



    const path = require("path");
    const multer = require('multer');
    const { document } = require('./../controllers');

    const diskStorage = multer.diskStorage({
    destination: function (req, file, callback) {
    callback(null, path.resolve("./server/uploads"))
    },
    filename: function (req, file, callback) {
    callback(null, file.originalname + '-' + Date.now() + ".csv")
    }
    });
    const uploadConfig = multer({
    storage: diskStorage,
    });

    const appRoutes = (app) => {
    app.post('/upload', uploadConfig.any(), document.upload);
    app.post('/process', document.process);
    app.get('/getFiles', document.getFiles);
    app.get('/getBatches/:fileId', document.getBatches);
    };

    module.exports = {
    appRoutes
    }









    share|improve this question

























      0












      0








      0








      I have an angular app in node that uses express to route various different http requests. I first ran into this problem when multiple users tried to upload files using the app at the same time. I first thought this was a problem with global scoped variables that reset the data of overlapping async/await requests.



      However, I was able to replicate this problem ("Failed to load resource: the server responded with a status of 400") with a curl to the same port on localhost, which is a default route to a get request. I thought express was supposed to be able to handle multiple http requests? Here is my middleware code in app.js:



      const PORT = 9001;
      const express = require("express");
      const bodyParser = require("body-parser");
      const app = express();
      const routes = require('./routes/routing');

      app.use((req, res, next) => {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "*");
      res.header("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE");
      next();
      });
      app.use(bodyParser.json({limit: '20mb', extended: true}))
      app.use(bodyParser.urlencoded({limit: '20mb', extended: true}))


      routes.appRoutes(app);


      app.get('/', function (req, res) {

      const example = ;

      for (i = 0; i < 1000; i++) {
      for (j = 0; j < 1000; j++) {
      example.push("test2");
      }
      example.push("test");
      }

      res.send(example);
      });


      app.all('*', function(req, res, next){
      res.send('Page not found.');
      });

      app.listen(PORT, () => {
      console.log("App is listening under the port: " + PORT);
      });


      and here is my routing.js:



      const path = require("path");
      const multer = require('multer');
      const { document } = require('./../controllers');

      const diskStorage = multer.diskStorage({
      destination: function (req, file, callback) {
      callback(null, path.resolve("./server/uploads"))
      },
      filename: function (req, file, callback) {
      callback(null, file.originalname + '-' + Date.now() + ".csv")
      }
      });
      const uploadConfig = multer({
      storage: diskStorage,
      });

      const appRoutes = (app) => {
      app.post('/upload', uploadConfig.any(), document.upload);
      app.post('/process', document.process);
      app.get('/getFiles', document.getFiles);
      app.get('/getBatches/:fileId', document.getBatches);
      };

      module.exports = {
      appRoutes
      }









      share|improve this question














      I have an angular app in node that uses express to route various different http requests. I first ran into this problem when multiple users tried to upload files using the app at the same time. I first thought this was a problem with global scoped variables that reset the data of overlapping async/await requests.



      However, I was able to replicate this problem ("Failed to load resource: the server responded with a status of 400") with a curl to the same port on localhost, which is a default route to a get request. I thought express was supposed to be able to handle multiple http requests? Here is my middleware code in app.js:



      const PORT = 9001;
      const express = require("express");
      const bodyParser = require("body-parser");
      const app = express();
      const routes = require('./routes/routing');

      app.use((req, res, next) => {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "*");
      res.header("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE");
      next();
      });
      app.use(bodyParser.json({limit: '20mb', extended: true}))
      app.use(bodyParser.urlencoded({limit: '20mb', extended: true}))


      routes.appRoutes(app);


      app.get('/', function (req, res) {

      const example = ;

      for (i = 0; i < 1000; i++) {
      for (j = 0; j < 1000; j++) {
      example.push("test2");
      }
      example.push("test");
      }

      res.send(example);
      });


      app.all('*', function(req, res, next){
      res.send('Page not found.');
      });

      app.listen(PORT, () => {
      console.log("App is listening under the port: " + PORT);
      });


      and here is my routing.js:



      const path = require("path");
      const multer = require('multer');
      const { document } = require('./../controllers');

      const diskStorage = multer.diskStorage({
      destination: function (req, file, callback) {
      callback(null, path.resolve("./server/uploads"))
      },
      filename: function (req, file, callback) {
      callback(null, file.originalname + '-' + Date.now() + ".csv")
      }
      });
      const uploadConfig = multer({
      storage: diskStorage,
      });

      const appRoutes = (app) => {
      app.post('/upload', uploadConfig.any(), document.upload);
      app.post('/process', document.process);
      app.get('/getFiles', document.getFiles);
      app.get('/getBatches/:fileId', document.getBatches);
      };

      module.exports = {
      appRoutes
      }






      javascript node.js express






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 16:07









      David LinDavid Lin

      224




      224
























          0






          active

          oldest

          votes












          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%2f53449835%2fmultiple-concurrent-http-requests-returning-a-400-bad-request%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f53449835%2fmultiple-concurrent-http-requests-returning-a-400-bad-request%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







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings