File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
packages/fresh/src/middlewares Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { getBuildCache } from "../context.ts";
1111 * app.use(staticFiles());
1212 * ```
1313 */
14- export function staticFiles < T > ( ) : Middleware < T > {
14+ export function staticFiles < T > ( serveDir = "/static" ) : Middleware < T > {
1515 return async function freshServeStaticFiles ( ctx ) {
1616 const { req, url, config } = ctx ;
1717
@@ -20,14 +20,17 @@ export function staticFiles<T>(): Middleware<T> {
2020
2121 let pathname = decodeURIComponent ( url . pathname ) ;
2222 if ( config . basePath ) {
23- pathname = pathname !== config . basePath
24- ? pathname . slice ( config . basePath . length )
25- : "/" ;
23+ pathname =
24+ pathname !== config . basePath
25+ ? pathname . slice ( config . basePath . length )
26+ : "/" ;
2627 }
2728
2829 // Fast path bail out
2930 const startTime = performance . now ( ) + performance . timeOrigin ;
30- const file = await buildCache . readFile ( pathname ) ;
31+
32+ const modifiedPath = pathname . replace ( "/static" , serveDir ) ;
33+ const file = await buildCache . readFile ( modifiedPath ) ;
3134 if ( pathname === "/" || file === null ) {
3235 // Optimization: Prevent long responses for favicon.ico requests
3336 if ( pathname === "/favicon.ico" ) {
You can’t perform that action at this time.
0 commit comments