summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Artyom Shalkhakov <artyom.shalkhakov@gmail.com>2019-01-07 16:45:46 +0200
committerGravatar Artyom Shalkhakov <artyom.shalkhakov@gmail.com>2019-01-07 16:45:46 +0200
commit6b3886a9cf4b0cc16d156cc5cb6b8b5ec9b85f05 (patch)
tree8d3ef1e1e37c9f449197a3d71c5e76ae67c63de6
parente6c93e5b8ed862d096d2120aa0be2a125b332776 (diff)
Including JS and other static files into endpoints
-rw-r--r--src/endpoints.sig2
-rw-r--r--src/endpoints.sml30
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