git.s-ol.nu mmm / 1e3b0a1
make security vulnerabilities optional, remove sandbox s-ol 2 years ago
15 changed file(s) with 43 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
1515 RUN tup init && tup generate --config tup.docker.config build-static.sh && ./build-static.sh
1616
1717 EXPOSE 8000
18 ENTRYPOINT ["moon", "build/server.moon", "fs", "0.0.0.0", "8000", "^/sandbox/"]
18 ENTRYPOINT ["moon", "build/server.moon", "fs", "0.0.0.0", "8000"]
77 add '?/init.server'
88
99 require 'mmm'
10 require 'mmm.mmmfs'
1110
1211 import dir_base, Key, Fileder from require 'mmm.mmmfs.fileder'
1312 import convert from require 'mmm.mmmfs.conversion'
2019 server = require 'http.server'
2120 headers = require 'http.headers'
2221
23 export UNSAFE
24
2522 class Server
2623 new: (@store, opts={}) =>
2724 opts = {k,v for k,v in pairs opts}
3027 opts.onstream = @\stream
3128 opts.onerror = @\error
3229
33 if opts.host == 'localhost'
34 UNSAFE = true
30 @server = server.listen opts
3531
36 @editable_paths = opts.editable_paths
32 @flags = opts.flags
3733
38 @server = server.listen opts
34 if @flags.rw == nil
35 @flags.rw = opts.host == 'localhost' or opts.host == '127.0.0.1'
36
37 if @flags.unsafe == nil
38 @flags.unsafe = opts.host == 'localhost' or opts.host == '127.0.0.1'
39
40 export UNSAFE
41 UNSAFE = @flags.unsafe
42 require 'mmm.mmmfs'
3943
4044 listen: =>
4145 assert @server\listen!
4246
4347 _, ip, port = @server\localname!
44 print "[#{@@__name}]", "running at #{ip}:#{port}"
48 print "[#{@@__name}]",
49 "running at #{ip}:#{port}",
50 "[#{table.concat [flag for flag,on in pairs @flags when on], ', '}]"
51
4552 assert @server\loop!
4653
4754 handle_interactive: (fileder, facet) =>
8794 -- fileder not found
8895 404, "fileder '#{path}' not found"
8996
90 if method != 'GET' and method != 'HEAD'
91 if not @editable_paths or not path\match @editable_paths
92 return 403, 'editing not allowed'
97 if not @flags.rw and method != 'GET' and method != 'HEAD'
98 return 403, 'editing not allowed'
9399
94100 switch method
95101 when 'GET', 'HEAD'
163169 msg = "#{msg}: #{err}" if err
164170
165171 -- usage:
166 -- moon server.moon [STORE] [host] [port] [editable-paths]
167 -- * STORE: see mmm/mmmfs/stores/init.moon:get_store
168 -- * host: interface to bind to (default localhost, set to 0.0.0.0 for public hosting)
169 -- * port: port to serve from, default 8000
170 -- * editable-paths: Lua pattern to match paths in which editing is allowed, default none
171 { store, host, port, editable_paths } = arg
172 -- moon server.moon [FLAGS] [STORE] [host] [port]
173 -- * FLAGS - any of the following:
174 -- --[no-]rw - enable/disable POST?PUT/DELETE operations (default: on if local)
175 -- --[no-]unsafe - enable/disable server-side code execution when writable is on (default: on if local)
176 -- * STORE - see mmm/mmmfs/stores/init.moon:get_store
177 -- * host - interface to bind to (default localhost, set to 0.0.0.0 for public hosting)
178 -- * port - port to serve from, default 8000
179
180 flags = {}
181 arguments = for a in *arg
182 if flag = a\match '^%-%-no%-(.*)$'
183 flags[flag] = false
184 continue
185 elseif flag = a\match '^%-%-(.*)$'
186 flags[flag] = true
187 continue
188 else
189 a
190
191 { store, host, port } = arguments
172192
173193 store = get_store store
174 server = Server store, :host, :editable_paths, port: port and tonumber port
194 server = Server store, :flags, :host, port: port and tonumber port
175195 server\listen!
0 export MODE, print, warn, relative, on_load
0 export MODE, UNSAFE, print, warn, relative, on_load
11 export window, document
22
33 window = js.global
44 { :document, :console } = window
55
66 MODE = 'CLIENT'
7 UNSAFE = true
78
89 deep_tostring = (tbl, space='') ->
910 return tbl if 'userdata' == type tbl
00 require = relative ..., 1
11 import Key from require '.fileder'
2 import converts, editors from require '.plugins'
32 import get_conversions, apply_conversions from require '.conversion'
43 import ReactiveVar, get_or_create, text, elements, tohtml from require 'mmm.component'
54 import pre, div, nav, span, button, a, code, option from elements
2827 transform: (href) => span a (code href), :href
2928 }
3029 }
31 casts = combine casts, converts, editors
30 get_casts = -> combine casts, PLUGINS.converts, PLUGINS.editors
3231
3332 export BROWSER
3433 class Browser
238237 value, key = @get prop
239238 assert key, "couldn't @get #{prop}"
240239
241 conversions = get_conversions 'mmm/dom', key.type, casts
240 conversions = get_conversions 'mmm/dom', key.type, get_casts
242241 assert conversions, "cannot cast '#{key.type}'"
243242 apply_conversions conversions, value, @, prop
244243
+0
-5
root/sandbox/description: text$markdown.md less more
0 Everything in this Fileder is world-editable on the internet.
1 It will be reset to its' default state whenever I push my repository.
2 Please behave.
3
4 Here is a list of this fileders content:
+0
-0
root/sandbox/dynamic-children/a/text$lua -> table less more
(Empty file)
+0
-0
root/sandbox/dynamic-children/b/text$markdown.md less more
(Empty file)
+0
-0
root/sandbox/dynamic-children/c/text$javascript -> text$markdown.js less more
(Empty file)
+0
-1
root/sandbox/dynamic-children/description: text$markdown.md less more
0 dynamically embedding children fileders with Lua
+0
-19
root/sandbox/dynamic-children/text$lua -> fn -> mmm$dom.lua less more
0 local d = require 'mmm.dom'
1 local u = require('mmm.mmmfs.util')(d)
2
3 -- we need to return a function to get access to the current fileder
4 -- (thats why there is the '-> fn ->' in the type)
5 return function(self)
6 local children = {}
7 for i, child in ipairs(self.children) do
8 table.insert(children, d.li {
9 'child ' .. i .. ': ',
10 u.link_to(child),
11 })
12 end
13
14 return d.article {
15 d.h1 'The Children are:',
16 d.ul(children),
17 }
18 end
+0
-1
root/sandbox/javascript/description: text$markdown.md less more
0 an example of how to use JS to create (dynamic) DOM / mmmfs content
+0
-24
root/sandbox/javascript/text$javascript -> mmm$dom.js less more
0 // a little helper function for creating DOM elements
1 const e = (elem, children) => {
2 const node = document.createElement(elem);
3
4 if (typeof children === 'string')
5 node.innerText = children;
6 else
7 children.forEach(child => node.appendChild(child));
8
9 return node;
10 };
11
12 /* creating the equivalent of the following HTML directly as DOM content:
13 *
14 * <article>
15 * <h1>JavaScript</h1>
16 * <p>...</p>
17 * </article>
18 */
19
20 return e('article', [
21 e('h1', 'JavaScript'),
22 e('p', 'JavaScript is supported natively in the browser but is not currently pre-rendered on the server.'),
23 ]);
+0
-1
root/sandbox/lua/description: text$markdown.md less more
0 an example of how to use Lua to create (dynamic) DOM / mmmfs content
+0
-10
root/sandbox/lua/text$lua -> mmm$dom.lua less more
0 -- see /meta/mmm.dom for documentation
1 local d = require 'mmm.dom'
2
3 local lua = d.a { 'Lua', href = 'https://www.lua.org/' }
4 local fengari = d.a { 'fengari.io', href = 'https://fengari.io/' }
5
6 return d.article {
7 d.h1 'Lua',
8 d.p { lua, ' is fully supported using ', fengari, ' on the Client.' }
9 }
+0
-18
root/sandbox/text$lua -> fn -> mmm$dom.lua less more
0 local d = require 'mmm.dom'
1 local u = require('mmm.mmmfs.util')(d)
2
3 return function(self)
4 local children = {}
5 for i, child in ipairs(self.children) do
6 table.insert(
7 children,
8 d.li(u.link_to(child), ': ', (child:get('description: mmm/dom')))
9 )
10 end
11
12 return d.div({
13 d.h3(u.link_to(self)),
14 self:gett('description: mmm/dom'),
15 d.ul(children),
16 })
17 end