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 doesn't work with deploy: "Request with GET/HEAD method cannot have body." #39

Closed orgsofthq closed 3 years ago

orgsofthq commented 3 years ago

The framework doesn't seem to work with serving static files while using Deno Deploy.

The body seems to be getting set somewhere, which causes an error when a new Request object is created. This doesn't seem to happen when using deployctl locally.

repro

mod.ts

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

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

http response

{"error":"Request with GET/HEAD method cannot have body."}

deploy logs

0 | [Info] | GET / 1ms 500
1 | [Error] | Error serving request: TypeError: Request with GET/HEAD method cannot have body.
     at new Request (deno:ext/fetch/23_request.js:323:15)
     at Object./ (https://deno.land/x/sift@0.3.5/mod.ts:138:36)
     at async handleRequest (https://deno.land/x/sift@0.3.5/mod.ts:63:36)
     at async Event.respondWith (deno:ext/http/01_http.js:151:16)
satyarohith commented 3 years ago

Thanks for opening the issue. This is now fixed in 0.4.0.

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

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

@satyarohith it seems like there is still an issue with the implementation.

Using the snippet above, I get..

"Not a directory (os error 20), open '[my_path]/index.html/'"

It tries to resolve to ./index.html/ instead of the intended ./index.html.

Lines 165-167 in mod.ts append a / to any route when params?.fileName is null, which it seems to always be.

satyarohith commented 3 years ago

@organic-software The issue is fixed in https://github.com/satyarohith/sift/pull/48. Try 0.4.1 and let me know if you still encounter the issue.