Skip to content

Commit 90f00c0

Browse files
committed
DASH_APP_NAME enviroment
1 parent 486f76a commit 90f00c0

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

src/utils/paths.jl

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ end
55

66
function app_root_path()
77
prog_path = program_path()
8-
8+
99
return isnothing(prog_path) ? pwd() : prog_path
1010
end
1111

1212
function pathname_configs(url_base_pathname, requests_pathname_prefix, routes_pathname_prefix)
13-
13+
1414
raise_error = (s) -> error("""
1515
$s This is ambiguous.
1616
To fix this, set `routes_pathname_prefix` instead of `url_base_pathname`.
@@ -42,15 +42,20 @@ function pathname_configs(url_base_pathname, requests_pathname_prefix, routes_pa
4242

4343
!startswith(routes_pathname_prefix, "/") && error("routes_pathname_prefix` needs to start with `/`")
4444
!endswith(routes_pathname_prefix, "/") && error("routes_pathname_prefix` needs to end with `/`")
45-
46-
if isnothing(requests_pathname_prefix)
45+
46+
app_name = dash_env("APP_NAME")
47+
48+
49+
if isnothing(requests_pathname_prefix) && !isnothing(app_name)
50+
requests_pathname_prefix = "/" * app_name * routes_pathname_prefix
51+
elseif isnothing(requests_pathname_prefix)
4752
requests_pathname_prefix = routes_pathname_prefix
4853
end
4954

5055
!startswith(requests_pathname_prefix, "/") &&
5156
error("requests_pathname_prefix` needs to start with `/`")
5257
!endswith(requests_pathname_prefix, routes_pathname_prefix) &&
5358
error("requests_pathname_prefix` needs to end with `routes_pathname_prefix`")
54-
59+
5560
return (url_base_pathname, requests_pathname_prefix, routes_pathname_prefix)
5661
end

test/config_functional.jl

+52-49
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ using HTTP
55

66

77

8-
@testset "external_stylesheets" begin
8+
@testset "external_stylesheets" begin
99
app = dash()
10-
resources = ApplicationResources(app, main_registry())
10+
resources = ApplicationResources(app, main_registry())
1111
index_page = Dash.index_page(app, resources)
12-
12+
1313
@test isnothing(findfirst("link rel=\"stylesheet\"", index_page))
14-
14+
1515
app = dash(external_stylesheets = ["https://test.css"])
16-
resources = ApplicationResources(app, main_registry())
16+
resources = ApplicationResources(app, main_registry())
1717
index_page = Dash.index_page(app, resources)
1818
@test !isnothing(findfirst("<link rel=\"stylesheet\" href=\"https://test.css\">", index_page))
1919

@@ -22,54 +22,57 @@ using HTTP
2222
Dict("href" => "https://test2.css", "rel" => "stylesheet")
2323
]
2424
)
25-
resources = ApplicationResources(app, main_registry())
25+
resources = ApplicationResources(app, main_registry())
2626
index_page = Dash.index_page(app, resources)
27-
27+
2828
@test !isnothing(findfirst("<link rel=\"stylesheet\" href=\"https://test.css\">", index_page))
2929
@test !isnothing(findfirst("href=\"https://test2.css\"", index_page))
30-
30+
3131
end
3232

3333
@testset "external_scripts" begin
34-
35-
34+
35+
3636
app = dash(external_scripts = ["https://test.js"])
37-
resources = ApplicationResources(app, main_registry())
37+
resources = ApplicationResources(app, main_registry())
3838
index_page = Dash.index_page(app, resources)
3939
@test !isnothing(findfirst("""<script src="https://test.js"></script>""", index_page))
4040

4141
app = dash(external_scripts = [
42-
"https://test.js",
42+
"https://test.js",
4343
Dict("src" => "https://test2.js", "crossorigin" => "anonymous")
4444
])
45-
resources = ApplicationResources(app, main_registry())
45+
resources = ApplicationResources(app, main_registry())
4646
index_page = Dash.index_page(app, resources)
4747

4848
@test !isnothing(findfirst("""<script src="https://test.js"></script>""", index_page))
49-
49+
5050
@test !isnothing(findfirst("""<script src="https://test2.js" crossorigin="anonymous"></script>""", index_page))
5151

5252
end
5353

5454
@testset "url paths" begin
55-
#=app = dash(requests_pathname_prefix = "/reg/prefix/", routes_pathname_prefix = "/prefix/")
56-
resources = ApplicationResources(app, main_registry())
57-
index_page = Dash.index_page(app, resources)
58-
59-
@test !isnothing(findfirst("""requests_pathname_prefix":"/reg/prefix/""", index_page))
60-
handler = Dash.make_handler(app)
61-
request = HTTP.Request("GET", "/prefix/")
62-
response = handler(request)
63-
@test response.status == 200
64-
65-
request = HTTP.Request("GET", "/prefix/_dash-layout")
66-
response = handler(request)
67-
@test response.status == 200
68-
69-
request = HTTP.Request("GET", "/prefix/_dash-dependencies")
70-
response = handler(request)
71-
@test response.status == 200=#
72-
55+
app = dash(requests_pathname_prefix = "/reg/prefix/", routes_pathname_prefix = "/prefix/")
56+
@test app.config.requests_pathname_prefix == "/reg/prefix/"
57+
@test app.config.routes_pathname_prefix == "/prefix/"
58+
59+
app = dash(routes_pathname_prefix = "/prefix/")
60+
@test app.config.routes_pathname_prefix == "/prefix/"
61+
@test app.config.requests_pathname_prefix == "/prefix/"
62+
63+
app = dash()
64+
@test app.config.routes_pathname_prefix == "/"
65+
@test app.config.requests_pathname_prefix == "/"
66+
67+
ENV["DASH_APP_NAME"] = "test-app"
68+
app = dash(routes_pathname_prefix = "/prefix/")
69+
@test app.config.routes_pathname_prefix == "/prefix/"
70+
@test app.config.requests_pathname_prefix == "/test-app/prefix/"
71+
72+
app = dash()
73+
@test app.config.routes_pathname_prefix == "/"
74+
@test app.config.requests_pathname_prefix == "/test-app/"
75+
7376
end
7477

7578
@testset "assets paths" begin
@@ -131,23 +134,23 @@ end
131134

132135
@testset "suppress_callback_exceptions" begin
133136
app = dash()
134-
resources = ApplicationResources(app, main_registry())
137+
resources = ApplicationResources(app, main_registry())
135138
index_page = Dash.index_page(app, resources)
136139
@test !isnothing(findfirst("\"suppress_callback_exceptions\":false", index_page))
137140
@test isnothing(findfirst("\"suppress_callback_exceptions\":true", index_page))
138141

139142
app = dash(suppress_callback_exceptions = true)
140-
resources = ApplicationResources(app, main_registry())
143+
resources = ApplicationResources(app, main_registry())
141144
index_page = Dash.index_page(app, resources)
142145
@test isnothing(findfirst("\"suppress_callback_exceptions\":false", index_page))
143146
@test !isnothing(findfirst("\"suppress_callback_exceptions\":true", index_page))
144147
end
145148

146149
@testset "meta_tags" begin
147150
app = dash()
148-
resources = ApplicationResources(app, main_registry())
151+
resources = ApplicationResources(app, main_registry())
149152
index_page = Dash.index_page(app, resources)
150-
153+
151154
@test !isnothing(
152155
findfirst(
153156
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
@@ -161,29 +164,29 @@ end
161164
)
162165

163166
app = dash(meta_tags = [Dict("type" => "tst", "rel" => "r")])
164-
resources = ApplicationResources(app, main_registry())
167+
resources = ApplicationResources(app, main_registry())
165168
index_page = Dash.index_page(app, resources)
166169

167170
@test !isnothing(
168171
findfirst(
169172
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
170173
index_page)
171174
)
172-
175+
173176
@test !isnothing(
174177
findfirst(
175178
"<meta charset=\"UTF-8\">",
176179
index_page)
177180
)
178-
181+
179182
@test !isnothing(
180183
findfirst(
181184
Dash.format_tag("meta", Dict("type" => "tst", "rel" => "r"), opened = true),
182185
index_page)
183186
)
184187

185188
app = dash(meta_tags = [Dict("charset" => "Win1251"), Dict("type" => "tst", "rel" => "r")])
186-
resources = ApplicationResources(app, main_registry())
189+
resources = ApplicationResources(app, main_registry())
187190
index_page = Dash.index_page(app, resources)
188191

189192
@test isnothing(
@@ -204,7 +207,7 @@ end
204207
)
205208

206209
app = dash(meta_tags = [Dict("http-equiv" => "X-UA-Compatible", "content" => "IE"), Dict("type" => "tst", "rel" => "r")])
207-
resources = ApplicationResources(app, main_registry())
210+
resources = ApplicationResources(app, main_registry())
208211
index_page = Dash.index_page(app, resources)
209212
@test isnothing(
210213
findfirst(
@@ -222,23 +225,23 @@ end
222225
@testset "index_string" begin
223226
index_string = "test test test, {%metas%},{%title%},{%favicon%},{%css%},{%app_entry%},{%config%},{%scripts%},{%renderer%}"
224227
app = dash(index_string = index_string)
225-
resources = ApplicationResources(app, main_registry())
228+
resources = ApplicationResources(app, main_registry())
226229
index_page = Dash.index_page(app, resources)
227-
@test startswith(index_page, "test test test,")
228-
230+
@test startswith(index_page, "test test test,")
231+
229232
end
230233

231234
@testset "show_undo_redo" begin
232-
235+
233236
app = dash()
234-
235-
resources = ApplicationResources(app, main_registry())
237+
238+
resources = ApplicationResources(app, main_registry())
236239
index_page = Dash.index_page(app, resources)
237240
@test !isnothing(findfirst("\"show_undo_redo\":false", index_page))
238241

239242
app = dash(show_undo_redo = true)
240-
241-
resources = ApplicationResources(app, main_registry())
243+
244+
resources = ApplicationResources(app, main_registry())
242245
index_page = Dash.index_page(app, resources)
243246
@test !isnothing(findfirst("\"show_undo_redo\":true", index_page))
244247
end

0 commit comments

Comments
 (0)