-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable hosting from subdirectory #771
base: master
Are you sure you want to change the base?
Enable hosting from subdirectory #771
Conversation
hmm, circleci fails with But I noticed that the code is already using the |
Ah I see, we need to tell eslint that the Instead of adding the |
@@ -35,7 +35,7 @@ function WebDAVForm() { | |||
persistField('webdavEndpoint', url); | |||
persistField('webdavUsername', username); | |||
persistField('webdavPassword', password); | |||
window.location = window.location.origin + '/'; | |||
window.location = window.location.origin + process.env.PUBLIC_URL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it behave if PUBLIC_URL is undefined instead of /
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch, thanks. It just turns into "" so the trailing slash would be missing. It looks like trailing slashes are removed from the PUBLIC_URL
anyway (for both the homepage
method and directly specifying PUBLIC_URL
) so I'll simply re-add the + '/'
after the PUBLIC_URL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, but does it also work for export PUBLIC_URL='/'
(which should be allowed IMO)? Sorry for that annoyance; I also don't have a solution by hand right now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I also tested that, this behaves the same as the other cases i.e. the slash is removed and PUBLIC_URL
ends up as "" which is what we want.
I was also wondering what would happen for a subdirectory that contains the string 'files', see this snippet in const fileParts = window.location.href.split('/').map((e) => decodeURIComponent(e));
if (_.includes(fileParts, 'files')) {
backPath = _.last(fileParts);
} Hosting this at instead of like this: There are however two remarks I have about this situation:
With the directory name being displayed somewhere else, we could then change the Therefore I don't think this issue is significant. |
As a server admin I want to host organice from a subdirectory URL in order to arrange my server's routes to my liking and to have more technical flexibility (i.e. host organice from the same domain as nextcloud so that I don't have to set up CORS).
This fixes issue #732.
This implementation uses CRA's
homepage
feature inpackage.json
. The person wanting to host organice from a subdomain should then adjust thehomepage
value to the full desired domain and path, for example"homepage": "https://example.com/organice/"
.After running
yarn build
as usual, they can then upload the resulting build output to that subdirectory on their server. Before this change, this was not possible because the router would have kept redirecting to the "/" route, the assets were not found, etc.Internally, CRA takes the
homepage
value and extracts the path part of it, which is then assigned toPUBLIC_URL
. It would also be possible to build organice without adjusting thehomepage
value and instead just callingPUBLIC_URL=/organice yarn build
.In my PR I left the
homepage
value as""
which should be safe as that should lead to the same behaviour as not specifying it. See the relevant implementation in CRA here (the code doesn't check for undefined, it just casts to bool).Do you want me to add some documentation for this? If yes, where? Should I add a new section in the FAQ for this?