-
Notifications
You must be signed in to change notification settings - Fork 40
Conversation
data/http-server-files.ts
Outdated
import { serve } from "$std/http/server.ts"; | ||
|
||
// Here we start a simple server | ||
console.log("Listening on http://localhost:8000"); |
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 message is duplicated as serve
already prints this
I think the example should be something like more primitive static file server without using import { serve } from "https://deno.land/std@0.175.0/http/server.ts";
serve(async (req: Request) => {
const pathname = new URL(req.url).pathname;
console.log("Got request to", pathname);
const fileUrl = new URL("." + pathname, import.meta.url);
try {
const stat = await Deno.lstat(fileUrl);
if (stat.isDirectory) {
return new Response("is directory"); // or primitive directory listing
}
const file = await Deno.open(fileUrl);
return new Response(file.readable);
} catch (e) {
return new Response("404: Not Found", {
status: 404,
});
}
}); (We are less interested in promoting |
Sounds good to me. I will update this PR when I get the chance. We should probably mention that the standard library has utility functions for this but otherwise agree with the point. |
I don't necessarily agree we don't want to showcase std/http/file_server here. It's probably what most people should be using. |
Now this gets to the question of "what is deno by example for?" My personal take is the deno by example is for beginners who want to learn the "correct" way to do a thing. If that's the view, I'd actually agree with Luca on this one. I think examples showing lower-level interactions make more sense in the deno manual instead of on the site. That was the conclusion of this (#45) rather short-lived issue, but I'm open to other perspectives. I think by example is really important for the beginner community. |
Ok. Then let's use utils from file_server.ts here |
Aren't we currently using utils from |
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.
Aren't we currently using utils from file_server.ts are you recommending we use primitives instead?
It's ok as it is. LGTM
No description provided.