git.s-ol.nu mmm / c138391
fix logging, 404 handling s-ol 10 months ago
1 changed file(s) with 6 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2727 opts.host = 'localhost' unless opts.host
2828 opts.port = 8000 unless opts.port
2929 opts.onstream = @\stream
30 opts.onerror = @\error
3130
3231 @server = server.listen opts
3332
107106 facet.type = base
108107 @handle_debug fileder, facet
109108 else if not fileder\has_facet facet.name
110 404, "facet '#{facet.name}' not found in fileder '#{path}'"
109 return 404, "facet '#{facet.name}' not found in fileder '#{path}'"
111110 else
112111 fileder\get facet
113112
123122 path = req\get ':path'
124123 path = decodeURI path
125124
126 path_facet, type = path\match '(.*):(.*)'
125 path_facet, typ = path\match '(.*):(.*)'
127126 path_facet or= path
128127 path, facet = path_facet\match '(.*)/([^/]*)'
129128
130 facet = if facet == '' and (not type or type == '') and method ~= 'GET' and method ~= 'HEAD'
129 facet = if facet == '' and (not typ or typ == '') and method ~= 'GET' and method ~= 'HEAD'
131130 nil
132131 else
133 type or= '?'
134 type = type\match '%s*(.*)'
135 Key facet, type
132 typ or= '?'
133 typ = typ\match '%s*(.*)'
134 Key facet, typ
136135
137136 value = stream\get_body_as_string!
138137 ok, status, body = xpcall @.handle, err_and_trace, @, method, path, facet, value
152151 stream\write_headers res, method == 'HEAD'
153152 if method ~= 'HEAD'
154153 stream\write_chunk body, true
155
156 error: (sv, ctx, op, err, errno) =>
157 msg = "#{op} on #{tostring ctx} failed"
158 msg = "#{msg}: #{err}" if err
159154
160155 -- usage:
161156 -- moon server.moon [FLAGS] [STORE] [host] [port]