summaryrefslogtreecommitdiff
path: root/http/file_server.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2019-02-16 01:03:57 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-02-15 11:03:57 -0500
commit57f4e6a86448263c9f1c75934e829e048c76f572 (patch)
treeb4e46dcb4a43fec2694e289702fba2cd5e475c50 /http/file_server.ts
parent34ece9f2ede9c63af2678feb15ef5290a74c8d2f (diff)
Redesign of http server module (denoland/deno_std#188)
Original: https://github.com/denoland/deno_std/commit/8569f15207bdc12c2c8ca81e9d020955be54918b
Diffstat (limited to 'http/file_server.ts')
-rwxr-xr-xhttp/file_server.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/http/file_server.ts b/http/file_server.ts
index 1f3fdd586..4aebd4957 100755
--- a/http/file_server.ts
+++ b/http/file_server.ts
@@ -10,7 +10,7 @@ import {
listenAndServe,
ServerRequest,
setContentLength,
- Response
+ ServerResponse
} from "./server.ts";
import { cwd, DenoError, ErrorKind, args, stat, readDir, open } from "deno";
import { extname } from "../fs/path.ts";
@@ -195,14 +195,14 @@ async function serveFallback(req: ServerRequest, e: Error) {
}
}
-function serverLog(req: ServerRequest, res: Response) {
+function serverLog(req: ServerRequest, res: ServerResponse) {
const d = new Date().toISOString();
const dateFmt = `[${d.slice(0, 10)} ${d.slice(11, 19)}]`;
const s = `${dateFmt} "${req.method} ${req.url} ${req.proto}" ${res.status}`;
console.log(s);
}
-function setCORS(res: Response) {
+function setCORS(res: ServerResponse) {
if (!res.headers) {
res.headers = new Headers();
}
@@ -213,11 +213,11 @@ function setCORS(res: Response) {
);
}
-listenAndServe(addr, async req => {
+listenAndServe(addr, async (req, res) => {
const fileName = req.url.replace(/\/$/, "");
const filePath = currentDir + fileName;
- let response: Response;
+ let response: ServerResponse;
try {
const fileInfo = await stat(filePath);
@@ -235,7 +235,7 @@ listenAndServe(addr, async req => {
setCORS(response);
}
serverLog(req, response);
- req.respond(response);
+ res.respond(response);
}
});