tus-node-server icon indicating copy to clipboard operation
tus-node-server copied to clipboard

Unable to run behind a reverse proxy

Open pablote opened this issue 3 years ago • 6 comments

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:

image

Going through the closed issues, I saw a fix mentioning an undocumented property relativeLocation, so I tried to set that to true:

image

image

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.

pablote avatar Sep 07 '20 19:09 pablote

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

Acconut avatar Sep 08 '20 08:09 Acconut

Did you ever get this working?

doomedramen avatar Dec 01 '20 14:12 doomedramen

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}`;

pablote avatar Dec 01 '20 15:12 pablote

Just use relative location and should work with uppy.

mitjap avatar May 27 '21 21:05 mitjap

@pablote @mitjap is this resolved or does this still require changes?

Murderlon avatar Jan 27 '22 14:01 Murderlon

This still needs changes.

mitjap avatar Jan 27 '22 14:01 mitjap