Ufs behind a reverse proxy
Huljo opened this issue ยท 21 comments
I'm trying to use ufs in a subfolder but the webapp handler is not catching my requests (ROOT_URL=http://www.domain.com/chat/
, meteor is running at localhost:3000, behind nginx).
console.log(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX) // "/sub"
console.log(UploadFS.config.storesPath) // "sub/ufs"
A POST request was sent to http://www.domain.com/sub/ufs/uploads/BnBYGCKsB9LBYqXeY?token=890B6b7B88&progress=1 by the client application but in the webapp handler ( here ) req.url
is set as "/ufs/uploads/BnBYGCKsB9LBYqXeY?token=890B6b7B88&progress=1" so req.url.indexOf(UploadFS.config.storesPath)
is returning -1 and skip the request treatment.
Hi @Huljo, I haven't verified this yet, but since your ROOT_URL
is a subfolder, I think it's normal from Meteor's point of view that any request does not contain the sub
folder, so your UploadFS.config.storesPath
should point to ufs
and not sub/ufs
.
It's what I think, because if you call Meteor.absoluteUrl()
you'll get http://www.domain.com/sub/
, then appending the storesPath
would repeat the sub folder like http://www.domain.com/sub/sub/ufs
.
I'll check that and confirm it to you.
Sorry for the late response.
Hi @jalik, thank you for your reply. no worries about the delay.
I set UploadFS.config.storesPath
to sub/ufs
because this is the better way I found to add a prefix before the URL used to send the POST request from the client.
If I set the value of UploadFS.config.storesPath
to ufs
, the client is calling http://www.domain.com/ufs/uploads/...
and nginx is returing 404 because my application is in the subfolder sub
@Huljo Sorry, I am working on some rework of the current code to use ES6 syntax (import/export and other handy syntaxes). I'll give a check this week !
@Huljo I fixed the bug in the 0.7.2
release, please update you packages.
It was not about reverse proxy but more a question of relative/absolute path defined by ROOT_URL
.
Using a subfolder was causing this issue.
I'll be back soon with the results of my tests (before the PR) :)
Hi @jalik, bad new, the client is still calling the URL "domain.com/ufs/uploads/..." in my case.
That sounds really weird.
Can you confirm that you have defined your ROOT_URL
to http://www.domain.com/chat
and your config option UploadFS.config.storesPath
to ufs
? (replace ufs
with your folder)
The POST URL where the client sends file chunks is returned by the server here :
https://github.com/jalik/jalik-ufs/blob/master/ufs-methods.js#L160
https://github.com/jalik/jalik-ufs/blob/master/ufs-store.js#L570-L575
In short the URL is built like that : ${rootUrl}/${UploadFS.config.storesPath}/${storeName}/${path}
So the final UFS's root URL would be http://www.domain.com/chat/ufs
and a store named files
would be http://www.domain.com/chat/ufs/files
.
I haven't checked the reverse proxy thing since it's kind of a pain to mount such a dev config to test it.. and also I think that it should be handled nicely if everything is setup correctly, but maybe I missed something...
Sorry for lack of detail, it was a quick test.
The only sure thing is that ufs is up to date (0.7.2) and ROOT_URL
is well defined to http://www.domain.com/chat
.
I'll make further testing the next hours.
Sorry for the delay.
When I set UploadFS.config.storesPath
to sub/ufs
the URL called on the client is now good (http://www.domain.com/sub/ufs/uploads/73ChKaf6zCLsm4AAw?token=9A3B5B1958&progress=1)
But the server is throwing an error :
Exception while invoking method 'ufsComplete' Error: ENOENT: no such file or directory, open '/tmp/ufs/73ChKaf6zCLsm4AAw'
hi @Huljo, the client is now good, and how about the issue "Can't upload files when running in a subdir #4832" on Rocket.chat ? I was struggling for it for a long time
@mattlin can you confirm that upload is working for you by only adding UFS 0.7.2 ?
It still not working in my case. Ill try to find some time to take a look at this ufsComplete method soon.
/tmp/ufs
is chown appuser:appuser
and chmod 700
. I can create a file in this folder using appuser permissions.
Do you have any idea about why the temporary file is missing @jalik ?
@Huljo I do not know how to add UFS 0.7.2 for Rocket.Chat. I will test the issue for Rocket.Chat new version.
Sorry for the delay @mattlin,
just change the version here :
https://github.com/RocketChat/Rocket.Chat/blob/1b7f93efbc1ba4c0cef799370b1074fc853a36df/.meteor/versions#L39
I've tried Rocket.Chat develop branch https://github.com/RocketChat/Rocket.Chat/blob/develop/.meteor/versions#L53 wich said jalik:ufs@0.7.4_1 and i still doesnt work - generates wrong POST url