-
Notifications
You must be signed in to change notification settings - Fork 6
/
xapp.lua
137 lines (104 loc) · 2.31 KB
/
xapp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--[==[
Canvas-UI-based Application Server.
Written by Cosmin Apreutesei. Public Domain.
LOADS
canvas-ui
USAGE
local myapp = require('xapp')(...)
....
return myapp:run(...)
PUBLISHES
myapp.schema
USES
function myapp:install() end
CONFIG
ignore_interrupts
host
dev_email
]==]
--NOTE: www_dirs must be set before any jsfile(), cssfile(), htmlfile() calls!
require'glue'
config('www_dirs', 'www;sdk/www;sdk/canvas-ui/www')
require'daemon'
require'webb_spa'
require'xrowset'
require'schema'
js[[
document.addEventListener('DOMContentLoaded', function init_all() {
init_action()
})
]]
jsfile[[
ui.js
ui_validation.js
ui_nav.js
ui_grid.js
adapter.js
webrtc.js
]]
require'xauth'
local function xapp(...)
local app = daemon(...)
function app:run_server()
app.server = webb_http_server()
start(config('ignore_interrupts', true))
end
function logging.rpc:close_all_sockets()
app.server:close_all_sockets()
close_all_dbs()
end
app.before = before
app.after = after
function app:run_cmd(cmd_name, cmd_fn, ...)
if cmd_name == 'run' then
return cmd_fn(cmd_name, ...)
end
return run(function(...)
local ok, err = pcall(cmd_fn, cmd_name, ...)
if not ok then --check500, assert, etc.
log('ERROR', 'xapp', 'run', '%s', err)
return 1
end
return err --exit_code
end, ...)
end
config('main_module', function()
checkfound(action(unpack(args())))
end)
app.schema = schema()
app.schema.env.null = null
app.schema.env.Sf = Sf
app.schema:import'schema_std'
app.schema:import'webb_auth'
sqlpps.mysql .define_symbol('current_timestamp', app.schema.env.current_timestamp)
sqlpps.tarantool.define_symbol('current_timestamp', app.schema.env.current_timestamp)
config('db_schema', app.schema)
if config('multilang', true) then
require'xlang'
end
cmd('install [forealz]', 'Install or migrate the app', function(opt, doit)
create_db()
local dry = doit ~= 'forealz'
db():sync_schema(app.schema, {dry = dry})
if not dry then
insert_or_update_row('tenant', {
tenant = 1,
name = 'default',
host = config'host',
})
if config'dev_email' then
usr_create_or_update{
tenant = 1,
email = config'dev_email',
roles = 'dev admin',
}
end
if app.install then
app:install()
end
end
say'Install done.'
end)
return app
end
return xapp