summaryrefslogtreecommitdiff
path: root/http/file_server.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-02-19 12:38:19 -0500
committerRyan Dahl <ry@tinyclouds.org>2019-02-19 13:18:41 -0500
commitd63a2e02246c0eb2ee6258b8fc32bbd0f9378567 (patch)
tree81b4019b47cc645887d738664578d2b2ff1facd3 /http/file_server.ts
parenta5a48ce84d255c8af57feb4b6a7f7ef607d16ee0 (diff)
Revert "Redesign of http server module (denoland/deno_std#188)"
We need to consider the API changes here more carefully. This reverts commit da188a7d30cbf71317b46015ee63a06437c09aeb. and commit 8569f15207bdc12c2c8ca81e9d020955be54918b. Original: https://github.com/denoland/deno_std/commit/57c9176b19bf4f4580466e088c249cbe9b145119
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 4aebd4957..1f3fdd586 100755
--- a/http/file_server.ts
+++ b/http/file_server.ts
@@ -10,7 +10,7 @@ import {
listenAndServe,
ServerRequest,
setContentLength,
- ServerResponse
+ Response
} 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: ServerResponse) {
+function serverLog(req: ServerRequest, res: Response) {
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: ServerResponse) {
+function setCORS(res: Response) {
if (!res.headers) {
res.headers = new Headers();
}
@@ -213,11 +213,11 @@ function setCORS(res: ServerResponse) {
);
}
-listenAndServe(addr, async (req, res) => {
+listenAndServe(addr, async req => {
const fileName = req.url.replace(/\/$/, "");
const filePath = currentDir + fileName;
- let response: ServerResponse;
+ let response: Response;
try {
const fileInfo = await stat(filePath);
@@ -235,7 +235,7 @@ listenAndServe(addr, async (req, res) => {
setCORS(response);
}
serverLog(req, response);
- res.respond(response);
+ req.respond(response);
}
});