tus-node-server
tus-node-server copied to clipboard
Unable to run behind a reverse proxy
I'm trying to run, without success, the tus server as an express middleware, behind a reverse proxy hosted in a URL other than "/".
On the server side:
const tusServer = new tus.Server();
tusServer.datastore = new tus.FileStore({
path: "/files"
});
const uploadApp = express();
uploadApp.all("*", tusServer.handle.bind(tusServer));
app.use("/uploads", uploadApp);
When I start an upload on the browser, it correctly creates it, but notice how /uploads
has a prefix path. The server responds with an incorrect location
, and the following PATCH request don't work well:
Going through the closed issues, I saw a fix mentioning an undocumented property relativeLocation
, so I tried to set that to true:
File creation still works and now it only returns the filename, but then the PATCH request fails, which although now includes the correct path prefix, I think it might be missing the "files/" part of it.
Am I doing anything wrong or missing something? thanks for the help.
Unfortunately, I cannot provide you steps to getting it working out of my head since I haven't used tus-node-server in a long time (I personally always recommend using tusd). However, maybe it helps you to look at the code responsible for extracting the ID from a URL: https://github.com/tus/tus-node-server/blob/e2c610a1abee30e7a120e2f3d9eedbafaa008260/lib/handlers/BaseHandler.js#L43-L51
Did you ever get this working?
I didn't go any further than a POC for this. But I did got it working by changing this line:
https://github.com/tus/tus-node-server/blob/master/lib/handlers/PostHandler.js#L19
with:
const url = this.store.relativeLocation ? `files/${File.id}` : `//${req.headers.host}${req.baseUrl || ''}${this.store.path}/${File.id}`;
Just use relative location and should work with uppy.
@pablote @mitjap is this resolved or does this still require changes?
This still needs changes.