1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-03 17:08:35 -05:00
denoland-deno/file_server.ts

19 lines
410 B
TypeScript
Raw Normal View History

2018-11-07 13:16:07 -05:00
import { listenAndServe } from "./http.ts";
import { open, cwd } from "deno";
const addr = "0.0.0.0:4500";
const d = cwd();
2018-11-07 14:17:36 -05:00
listenAndServe(addr, async req => {
2018-11-07 13:16:07 -05:00
const filename = d + "/" + req.url;
let res;
try {
res = { status: 200, body: open(filename) };
2018-11-07 14:17:36 -05:00
} catch (e) {
2018-11-07 13:16:07 -05:00
res = { status: 500, body: "bad" };
}
req.respond(res);
});
console.log(`HTTP server listening on http://${addr}/`);