urlToRelativePath() in Adapters seems wrong if express mountpoint is not / #6

Closed
opened 2024-07-21 09:56:13 -07:00 by nebulade · 3 comments
nebulade commented 2024-07-21 09:56:13 -07:00 (Migrated from github.com)

Hi, first off, thanks for the great module!

The code works fine when mounted on /.

I was trying to mount nephele in a subpath on express:

app.use('/webdav', nephele({
            adapter: new FileSystemAdapter({
                root: '/data/root/',
            }),
            authenticator: new InsecureAuthenticator(),
        })
}; 

This in turn will, as expected, hit https://github.com/sciactive/nephele/blob/master/packages/adapter-file-system/src/Adapter.ts#L87 in various places.

The issue is, that the url in express.js would already have the mountpoint (ie baseurl) removed from the path when hitting nephele. So the check for path having baseUrl fails. Skipping that prefix check and also removing the subsequent .substring(decodeURIComponent(baseUrl.pathname).length) will fix the issue.

Further code handles listing and at least retrieving files and contents fine, but after some debugging, I couldn't quite find how the absolute paths (which are wrong, as they contain the mountpoint) are constructed. Writing files does not work as the absolute path ends up being wrong.

Maybe I am hitting some unsupported path here, but should nephele work with the filesystem adapter on an express mountpoint in the first place?

Happy to do further debugging if this is not easily reproducible or I have some more pointers in the right direction.

Hi, first off, thanks for the great module! The code works fine when mounted on `/`. I was trying to mount nephele in a subpath on express: ``` app.use('/webdav', nephele({ adapter: new FileSystemAdapter({ root: '/data/root/', }), authenticator: new InsecureAuthenticator(), }) }; ``` This in turn will, as expected, hit https://github.com/sciactive/nephele/blob/master/packages/adapter-file-system/src/Adapter.ts#L87 in various places. The issue is, that the url in express.js would already have the mountpoint (ie baseurl) removed from the path when hitting nephele. So the check for path having baseUrl fails. Skipping that prefix check and also removing the subsequent `.substring(decodeURIComponent(baseUrl.pathname).length)` will fix the issue. Further code handles listing and at least retrieving files and contents fine, but after some debugging, I couldn't quite find how the absolute paths (which are wrong, as they contain the mountpoint) are constructed. Writing files does not work as the absolute path ends up being wrong. Maybe I am hitting some unsupported path here, but should nephele work with the filesystem adapter on an express mountpoint in the first place? Happy to do further debugging if this is not easily reproducible or I have some more pointers in the right direction.
hperrin commented 2024-10-12 10:58:47 -07:00 (Migrated from github.com)

I'm going to look into this today. Thank you for the report.

I'm going to look into this today. Thank you for the report.
hperrin commented 2024-10-12 12:25:38 -07:00 (Migrated from github.com)

Fixed! I used originalUrl from Express instead of url.

Fixed! I used `originalUrl` from Express instead of `url`.
nebulade commented 2024-10-13 07:44:27 -07:00 (Migrated from github.com)

Awesome, thank you very much!

Awesome, thank you very much!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sciactive/nephele#6
No description provided.