diff --git a/pjs/config.json b/pjs/config.json index 739576e..e083649 100644 --- a/pjs/config.json +++ b/pjs/config.json @@ -1,6 +1,7 @@ { "Configs": { - "EnableDebug": true + "EnableDebug": true, + "DefaultMimeType": "application/xhtml+xml" }, "Listeners": [ { @@ -35,8 +36,10 @@ }, "8081": { "*": { + "DefaultMimeType": "text/plain", "Matches": [ { + "DefaultMimeType": "text/html", "ServerRoot": "/var/www/html", "Index": [ "index.html", @@ -58,7 +61,7 @@ "ServerRoot": "www2", "Index": [ "default.html", - "index.htm" + "index.html" ] } ] @@ -155,4 +158,4 @@ ] }, "Version": "0" -} +} \ No newline at end of file diff --git a/pjs/server/web-server.js b/pjs/server/web-server.js index 05b07af..9340eaa 100644 --- a/pjs/server/web-server.js +++ b/pjs/server/web-server.js @@ -1,5 +1,5 @@ (( - { isDebugEnabled } = pipy.solve('config.js'), + { config, isDebugEnabled } = pipy.solve('config.js'), extTypes = ((mime = JSON.decode(pipy.load('files/mime.json'))) => ( Object.fromEntries( @@ -13,14 +13,24 @@ ) ))(), - matchContentType = ext => ( - (ext === '') ? ( - 'text/html' - ) : ( - extTypes?.[ext] || 'application/octet-stream' + defaultMimeTypeCache = new algo.Cache( + route => ( + route?.config?.DefaultMimeType ? ( + route.config.DefaultMimeType + ) : ( + __domain?.DefaultMimeType ? ( + __domain.DefaultMimeType + ) : ( + config?.Configs?.DefaultMimeType + ) + ) ) ), + matchContentType = ext => ( + extTypes?.[ext] || defaultMimeTypeCache.get(__route) || 'application/octet-stream' + ), + checkFileMode = filepath => ( ( s = os.stat(filepath) @@ -113,6 +123,7 @@ }) .import({ + __domain: 'route', __route: 'route', }) @@ -133,7 +144,7 @@ ) ) ), - _message || new Message({ status: 404 }, 'Not Found') + _message || new Message({ status: 404 }, 'Not Found') ) ) .branch( @@ -146,4 +157,4 @@ ) ) -)() \ No newline at end of file +)()