Skip to content

Commit 60f17c1

Browse files
committed
static files dir is now configurable.
1 parent fa6f4f4 commit 60f17c1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/fresh/src/middlewares/static_files.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff 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") {

0 commit comments

Comments
 (0)