'how to redirect large file requests through node.js to a different server using request
I have a node.js server that is forwarding API requests through to another server on a different port (so that auth cookies and the like make it across), and this has all worked great until the client has needed to upload a large file (> 100mb).
When I try to do that, if the file is over ~30mb the request never even reaches the far server (which will happily accept large files when connected to directly), so I'm pretty sure it's dying in node ... somewhere.
"use strict";
const http = require("http");
const port = process.env.FRONTEND_PORT || 13370;
const path = require("path");
const request = require("request");
const express = require("express");
const app = express();
const staticPath = path.join(__dirname, "/dist/");
app.set("port", port);
// Attempt to set some ridiculously high limits on things
app.use(express.urlencoded({parameterLimit: 1000000, limit: '10gb', extended: true}));
app.use(express.json({limit: '10gb'}));
// Serve files from this location
app.use(express.static(staticPath));
app.use(
'/api',
(req, res) =>
{
var url = "https://localhost:12121/api" + req.url;
req.pipe(request(url)).pipe(res);
console.log(res.statusCode);
console.log(res.statusMessage);
});
// If we hit any path that doesn't exist, instead serve up index.html and let react router handle it
app.get("*", (req, res) => { res.sendFile(path.join(__dirname, "/dist/index.html")); });
app.listen(app.get("port"), () => { console.log("listening"); });
As you can see, I've tried bumping up the limits (based on other SO answers I've seen) using:
app.use(express.urlencoded({parameterLimit: 1000000, limit: '10gb', extended: true}));
app.use(express.json({limit: '10gb'}));
...but this doesn't seem to be helping me in this case. I'm sure I'm missing something obvious, but I am extremely new to node.js (and, honestly, web development in general).
(It's also worth noting, the file is being sent through a basic XMLHttpRequest as POST, sending a File object through - nothing fancy going on there)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
