aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-10-10 18:54:42 +0000
committers-ol <s-ol@users.noreply.github.com>2019-10-10 18:54:42 +0000
commit005cc9b3914128267017620984aee921999e173f (patch)
treed6253b9ff1129dd2e61323df31a79f39a4eb57e7 /build
parentfix bug with _, - in facet names (diff)
downloadmmm-005cc9b3914128267017620984aee921999e173f.tar.gz
mmm-005cc9b3914128267017620984aee921999e173f.zip
move static files into root/
Diffstat (limited to 'build')
-rw-r--r--build/server.moon52
1 files changed, 0 insertions, 52 deletions
diff --git a/build/server.moon b/build/server.moon
index 983b43b..ca08874 100644
--- a/build/server.moon
+++ b/build/server.moon
@@ -76,64 +76,12 @@ class Server
else
501, "not implemented"
- handle_static: (method, path, stream) =>
- path = path\match '^/%.static/(.*)'
- return unless path
-
- respond = (code, type, body) ->
- res = headers.new!
- res\upsert ':status', code
- res\append 'content-type', type
-
- assert stream\write_headers res, method == 'HEAD'
- if body and method ~= 'HEAD'
- assert stream\write_body_from_string body
-
- if method ~= 'GET' and method ~= 'HEAD'
- respond '405', 'text/plain', "can only GET/HEAD static resources"
- return true
-
- if path\match '%.%.' or path\match '^%~'
- respond '404', 'text/plain', "not found"
- return
-
- file_path = "static/#{path}"
- if 'file' == lfs.attributes file_path, 'mode'
- fd, err, errno = io.open file_path, 'rb'
-
- if not fd
- code = switch errno
- when ce.ENOENT then '404'
- when ce.EACCES then '403'
- else '503'
-
- respond code, 'text/plain', err or ''
-
- else
- suffix = file_path\match '%.([a-z]+)$'
- type = switch suffix
- when 'css' then 'text/css'
- when 'lua' then 'application/lua'
- when 'js' then 'application/javascript'
- else 'application/octet-stream'
-
- respond '200', type, nil
- if method ~= 'HEAD'
- assert stream\write_body_from_file fd
- else
- respond '404', 'text/plain', "not found"
-
- true
-
stream: (sv, stream) =>
req = stream\get_headers!
method = req\get ':method'
path = req\get ':path'
path = decodeURI path
- -- serve static assets, cheap hack for now
- return if @handle_static method, path, stream
-
path_facet, type = path\match '(.*):(.*)'
path_facet or= path
path, facet = path_facet\match '(.*)/([^/]*)'