From 6b3886a9cf4b0cc16d156cc5cb6b8b5ec9b85f05 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Mon, 7 Jan 2019 16:45:46 +0200 Subject: Including JS and other static files into endpoints --- src/endpoints.sig | 2 +- src/endpoints.sml | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/endpoints.sig b/src/endpoints.sig index d766eb43..852f78ce 100644 --- a/src/endpoints.sig +++ b/src/endpoints.sig @@ -30,7 +30,7 @@ signature ENDPOINTS = sig datatype method = GET | POST val methodToString : method -> string - type endpoint = {Method : method, Url : string} + type endpoint = {Method : method, Url : string, ContentType : string option, LastModified : Time.time option} val p_endpoint : endpoint Print.printer type report = {Endpoints : endpoint list} diff --git a/src/endpoints.sml b/src/endpoints.sml index 22186cbb..c4a31738 100644 --- a/src/endpoints.sml +++ b/src/endpoints.sml @@ -37,14 +37,20 @@ datatype method = GET | POST fun methodToString GET = "GET" | methodToString POST = "POST" -type endpoint = {Method : method, Url : string} +type endpoint = {Method : method, Url : string, ContentType : string option, LastModified : Time.time option} type report = {Endpoints : endpoint list} -fun p_endpoint {Method = m, Url = u} = - box [string "{", - string "\"method\": \"", string (methodToString m), string "\",", - string "\"url\": \"", string u, string "\"", - string "}"] +fun p_endpoint {Method = m, Url = u, ContentType = oct, LastModified = olm} = + let + val rfcFmt = "%a, %d %b %Y %H:%M:%S GMT" + in + box [string "{", + string "\"method\": \"", string (methodToString m), string "\", ", + string "\"url\": \"", string u, string "\", ", + string "\"content-type\": ", (case oct of SOME ct => box [string "\"", string ct, string"\""] + | NONE => string "null"), + string "}"] + end fun p_report {Endpoints = el} = box [string "{\"endpoints\":", @@ -65,12 +71,22 @@ fun summarize file = in case d of DExport (ek, id, i, tl, rt, f) => - {Method = exportKindToMethod ek, Url = id} :: st + {Method = exportKindToMethod ek, Url = id, LastModified = NONE, ContentType = NONE} :: st | _ => st end val (decls, _) = file val ep = foldl decl [] decls + + fun binfile ({Uri = u, ContentType = ct, LastModified = lm, Bytes = _ }, st) = + {Method = GET, Url = u, LastModified = SOME lm, ContentType = ct} :: st + + val ep = foldl binfile ep (Settings.listFiles ()) + + fun jsfile ({Filename = f, Content = _}, st) = + {Method = GET, Url = f, LastModified = NONE, ContentType = SOME "text/javascript"} :: st + + val ep = foldl jsfile ep (Settings.listJsFiles ()) in {Endpoints = ep} end -- cgit v1.2.3