@@ -10,12 +10,49 @@ class Server < Sinatra::Base
10
10
set :protection , except : :frame_options
11
11
ZENDESK_DOMAINS_REGEX = %r{^http(?:s)?://[a-z0-9-]+\. (?:zendesk|zopim|futuresimple|local.futuresimple|zendesk-(?:dev|master|staging))\. com$}
12
12
13
+ get '/app.json' do
14
+ server_installed_json
15
+ end
16
+
13
17
get '/app.js' do
14
18
serve_installed_js
15
19
end
16
20
17
21
enable :cross_origin
18
22
23
+ def server_installed_json
24
+ access_control_allow_origin
25
+ content_type 'text/javascript'
26
+
27
+ new_settings = settings . settings_helper . refresh!
28
+ settings . parameters = new_settings if new_settings
29
+
30
+ package = ZendeskAppsSupport ::Package . new ( settings . root , false )
31
+ app_name = package . manifest . name || 'Local App'
32
+
33
+ app_obj = package . obj (
34
+ app_id : settings . app_id ,
35
+ app_name : app_name ,
36
+ assets_dir : "http://localhost:#{ settings . port } /" ,
37
+ locale : params [ 'locale' ]
38
+ )
39
+
40
+ installation = {
41
+ app_id : settings . app_id ,
42
+ app_name : app_name ,
43
+ collapsible : true ,
44
+ created_at : Time . now . iso8601 ,
45
+ enabled : true ,
46
+ id : settings . app_id ,
47
+ plan : { name : settings . plan } ,
48
+ requirements : package . requirements_json ,
49
+ settings : settings . parameters . merge ( title : app_name ) ,
50
+ updated_at : Time . now . iso8601
51
+ }
52
+
53
+ ZendeskAppsSupport ::Installed . new ( [ app_obj ] , [ installation ] ) . obj . to_json
54
+ end
55
+
19
56
def serve_installed_js
20
57
access_control_allow_origin
21
58
content_type 'text/javascript'
0 commit comments