-
-
Notifications
You must be signed in to change notification settings - Fork 756
feat(serve-static): use join
to correct path resolution
#4291
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4291 +/- ##
==========================================
- Coverage 91.61% 91.52% -0.10%
==========================================
Files 170 171 +1
Lines 10875 10792 -83
Branches 3099 3113 +14
==========================================
- Hits 9963 9877 -86
- Misses 911 914 +3
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -79,7 +79,8 @@ describe('ServeStatic Middleware', () => { | |||
expect(res.headers.get('Content-Type')).toBe('text/plain; charset=utf-8') | |||
}) | |||
|
|||
it('Should return index.html', async () => { | |||
// Serve static on Cloudflare Workers cannot determine whether the target path is a directory or not | |||
it.skip('Should return index.html', async () => { |
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.
In the previous implementation, if the file was not found, it checked whether index.html
existed. This PR, that process has been removed.
Since serve static for Cloudflare Workers is deprecated and not planned to be used, this change is acceptable.
Hey @usualoma ! What do you think of this? If it makes sense for you, please review it! |
Hi @yusukebe |
@usualoma Okay! |
Hi @yusukebe Reasons for not using ‘node:path’ in denoI think the reason is probably because we haven't used modules in the "node:" namespace in this file before, but is that correct? (We have already used them in bun.) If that is the case, as mentioned below, I think it's better to always use
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Bundle size check
Compiler Diagnostics (tsc)
Compiler Diagnostics (typescript-go)
Reported by octocov |
HTTP Performance Benchmark
|
@@ -1,3 +1,4 @@ | |||
import { join } from 'node:path' |
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.
We can use @std/path, but it's better to use node:path
because it's built into Deno.
expect(await res.text()).toBe('Hello in ./static/sub/index.html') | ||
}) | ||
|
||
it('Should return 200 response - /static/helloworld', async () => { |
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.
This test is the same as Should return 200 response - /static/sub
?? We may remove this.
Hi @usualoma Thank you for the accurate comment! For Deno, as you said, we can use For the separators issue, I made What do you think of this? |
This PR introduces a new mechanism for the serve static middleware. This can fix unintended path resolution.
pathResolve
optionjoin
optionsrc/middleware/serve-static/index.ts
defaultJoin
. It is used if thejoin
option is not specifiedIt is inspired by honojs/node-server#261
Problems
In previous implementations, paths starting with
C:\Users\yusuke\
on Windows were converted to/Users/yusuke
. This caused unintended behavior because the drive name was lost.If we use a function such as
join
exported bypath:node
, we can solve this problem and simplify the code. ThepathResolve
option is also unnecessary.Breaking changes?
I changed the test code, but only
path
passed toonFound
andonNotFound
has been slightly changed.Other behaviors remain unchanged. Additionally, unexpected path resolution issues should be resolved immediately. Release a minor version without changing the major version.
The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code