-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix: normalize API routes using Rust path entities #32
Conversation
I found an error when testing subfolders in Windows. It's using the |
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.
Looking great, lots of tests! A couple of comments :)
…ions into a single one.
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.
LGTM, thanks @Angelmmiguel! It looks great! Just a small optional comment about the GH workflow setup
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.
🎉
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.
Ship it!
In the current
main
version, file paths are not normalized properlies as APIs. This is causing inconsistent behaviors in different environments:wws ./examples/js-basic
, the URL of thehandler.js
should be/handler
. Note that./examples/js-basic
is the local folder to read the files, not a prefix for the final URL. However, the HTTP endpoint it generates is `/examples/js-basic/handler.handler.js
is not accessible (See [1]).This is mainly caused by converting file paths to string and apply transformations later. Since paths may include special components such as
.
and./
, applying operations likereplace
can have different outcomes depending on the environment. This also causes inconsistent behaviors when a final backslash is added or not to the CLI argument.In this PR, I changed that implementation to run all required transformations directly on the path. Instead of replacing and subtracting from a converted string, I iterate over the components to remove any special entity and keep only the Normal ones. Finally, I convert them to a String to be used as the API path.
I tested the current changes on both Windows and Mac (Unix) and they work great:
[1]
It closes #30