git.s-ol.nu mmm / 97bc4a0
make live server load subtree just-in-time (for live refreshing) s-ol 3 years ago
3 changed file(s) with 7 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3333 'null'
3434
3535 class Server
36 new: (@tree, opts={}) =>
36 new: (@store, opts={}) =>
3737 opts = {k,v for k,v in pairs opts}
3838 opts.host = 'localhost' unless opts.host
3939 opts.port = 8000 unless opts.port
5050 assert @server\loop!
5151
5252 handle: (method, path, facet) =>
53 fileder = @tree\walk path
53 fileder = load_tree @store, path -- @tree\walk path
5454 switch method
5555 when 'GET', 'HEAD'
5656 if fileder and facet
167167 { store, host, port } = arg
168168
169169 store = get_store store
170 tree = load_tree store
171 server = Server tree, :host, port: port and tonumber port
170 server = Server store, :host, port: port and tonumber port
172171 server\listen!
129129 <html>
130130 <head>
131131 <link rel="stylesheet" type="text/css" href="/.static/main.css" />
132 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400" />
132 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />
133133 ]]
134134 buf ..= "
135135 #{get_meta fileder}
33 -- e.g.: sql, fs:/path/to/root, sql:MEMORY, sql:db.sqlite3
44 get_store = (args='sql', opts={verbose: true}) ->
55 type, arg = args\match '(%w+):(.*)'
6 type = arg unless type
6 type = args unless type
77
88 switch type\lower!
99 when 'sql'
1717 SQLStore opts
1818
1919 when 'fs'
20 import LFSStore from require '.fs'
20 import FSStore from require '.fs'
2121
2222 opts.root = arg
2323
24 LFSStore opts
24 FSStore opts
2525
2626 else
2727 warn "unknown or missing value for STORE: valid types values are sql, fs"