aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/HttpServer.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-04-06 05:32:18 +0300
committerRblSb <msrblsb@gmail.com>2020-04-06 05:32:37 +0300
commit1b269aa5c990ded5aaae773a78daf5230d47a5e2 (patch)
tree4db3e5e8ef0c8ce7928c87b10b8282d975593af2 /src/server/HttpServer.hx
parentdb1c5a4523acb1d4a47773a8261930037153c309 (diff)
Fix folder links for user folder
Diffstat (limited to 'src/server/HttpServer.hx')
-rw-r--r--src/server/HttpServer.hx23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx
index a5b752b..ec6ddda 100644
--- a/src/server/HttpServer.hx
+++ b/src/server/HttpServer.hx
@@ -48,13 +48,9 @@ class HttpServer {
if (url == "/") url = "/index.html";
var filePath = dir + url;
- final extension = Path.extension(filePath).toLowerCase();
- final contentType = getMimeType(extension);
-
if (req.connection.remoteAddress == req.connection.localAddress
|| allowedLocalFiles[url]) {
- final isExists = serveLocalFile(res, url, extension, contentType);
- if (isExists) return;
+ if (serveLocalFile(res, url)) return;
}
if (!isChildOf(dir, filePath)) {
@@ -66,7 +62,12 @@ class HttpServer {
if (hasCustomRes) {
final path = customDir + url;
- if (Fs.existsSync(path)) filePath = path;
+ if (Fs.existsSync(path)) {
+ filePath = path;
+ if (FileSystem.isDirectory(filePath)) {
+ filePath = Path.addTrailingSlash(filePath) + "index.html";
+ }
+ }
}
Fs.readFile(filePath, (err:Dynamic, data:Buffer) -> {
@@ -74,8 +75,9 @@ class HttpServer {
readFileError(err, res, filePath);
return;
}
- res.setHeader("Content-Type", contentType);
- if (extension == "html") {
+ final ext = Path.extension(filePath).toLowerCase();
+ res.setHeader("Content-Type", getMimeType(ext));
+ if (ext == "html") {
// replace ${textId} to localized strings
data = cast localizeHtml(data.toString(), req.headers["accept-language"]);
}
@@ -94,7 +96,8 @@ class HttpServer {
}
}
- static function serveLocalFile(res:ServerResponse, filePath:String, ext:String, contentType:String):Bool {
+ static function serveLocalFile(res:ServerResponse, filePath:String):Bool {
+ final ext = Path.extension(filePath).toLowerCase();
if (ext != "mp4" && ext != "mp3" && ext != "wav") return false;
if (!Fs.existsSync(filePath)) return false;
allowedLocalFiles[filePath] = true;
@@ -103,7 +106,7 @@ class HttpServer {
readFileError(err, res, filePath);
return;
}
- res.setHeader("Content-Type", contentType);
+ res.setHeader("Content-Type", getMimeType(ext));
res.end(data);
});
return true;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage