satyarohith / sift

Sift is a routing and utility library for Deno Deploy.
https://deno.land/x/sift
MIT License
170 stars 14 forks source link

serveStatic for single file is not work #49

Closed hashrock closed 3 years ago

hashrock commented 3 years ago

version: sift 0.4.1, deno 1.15.2, Ubuntu with WSL

Repro

code(retrieved from the documentation):

import { serve, serveStatic } from "https://deno.land/x/sift@0.4.1/mod.ts";

serve({
  "/test": serveStatic("public/index.html", { baseUrl: import.meta.url }),
});

and I opened http://localhost:8000/test

then I got:

Error serving request: Error: Not a directory (os error 20), open '/mnt/c/code/deno/study-deploy-sift/public/index.html/undefined'
    at async open (deno:runtime/js/40_files.js:51:17)
    at async Object.readFile (deno:runtime/js/40_read_file.js:20:18)
    at async Object./test (https://deno.land/x/sift@0.4.1/mod.ts:176:20)
    at async handleRequest (https://deno.land/x/sift@0.4.1/mod.ts:79:24)
    at async Server.#respond (https://deno.land/std@0.111.0/http/server.ts:350:24)
GET /test 6ms 500
satyarohith commented 3 years ago

@hashrock, thanks for opening the issue. The fix seems to be not published to the registry. I created a tag with broken code and re-created it on GitHub, but the registry has the old tag hence the bug. Check out 0.4.2.

import { serve, serveStatic } from "https://deno.land/x/sift@0.4.2/mod.ts";

serve({
  "/test": serveStatic("public/index.html", { baseUrl: import.meta.url }),
});
hashrock commented 3 years ago

It works! Thank you👍