diff --git a/conftest.py b/conftest.py
index 2f2451b..326a08c 100644
--- a/conftest.py
+++ b/conftest.py
@@ -90,6 +90,7 @@ def webapp():
# initialize
server_url = pytest.config.option.server_url #pylint: disable=no-member
+ app.base_url = server_url if server_url else "http://localhost:{}".format(FLASK_WEBAPP_PORT)
logging.disable( logging.CRITICAL )
# initialize
@@ -113,10 +114,7 @@ def webapp():
# to avoid problems if something else uses the clipboard while the tests are running.
kwargs["store_clipboard"] = 1
url = url_for( endpoint, _external=True, **kwargs )
- if server_url:
- url = url.replace( "http://localhost", server_url )
- else:
- url = url.replace( "localhost/", "localhost:{}/".format(FLASK_WEBAPP_PORT) )
+ url = url.replace( "http://localhost", app.base_url )
return url
app.url_for = make_webapp_url
diff --git a/vasl_templates/webapp/main.py b/vasl_templates/webapp/main.py
index dbd9b2b..ef01bb6 100644
--- a/vasl_templates/webapp/main.py
+++ b/vasl_templates/webapp/main.py
@@ -80,6 +80,14 @@ def get_app_config():
for key in ["APP_NAME","APP_VERSION","APP_DESCRIPTION","APP_HOME_URL"]:
vals[ key ] = getattr( vasl_templates.webapp.config.constants, key )
+ # NOTE: We allow the front-end to generate snippets that point to an alternative webapp server (so that
+ # VASSAL can get images, etc. from a Docker container rather than the desktop app). However, since it's
+ # unlikely anyone else will want this option, we implement it as a debug setting, rather than exposing it
+ # as an option in the UI.
+ alt_webapp_base_url = app.config.get( "ALTERNATE_WEBAPP_BASE_URL" )
+ if alt_webapp_base_url:
+ vals[ "ALTERNATE_WEBAPP_BASE_URL" ] = alt_webapp_base_url
+
# include information about VASSAL and VASL
from vasl_templates.webapp.vassal import VassalShim
try:
diff --git a/vasl_templates/webapp/static/css/main.css b/vasl_templates/webapp/static/css/main.css
index 7578a1b..cf584ee 100644
--- a/vasl_templates/webapp/static/css/main.css
+++ b/vasl_templates/webapp/static/css/main.css
@@ -18,6 +18,10 @@ label { height: 1.25em ; margin-top: -3px ; }
.PopMenu-Item a { padding: 5px 10px 5px 10px ; }
.PopMenu-Icon { display: none ; }
+#alt-webapp-base-url { position: absolute ; top: 30px ; right: 110px ;
+ font-size: 80% ; font-style: italic ; color: #cc0000 ;
+}
+
#watermark { position: absolute ; left: 8px ; right: 8px ; bottom: 6px ; height: 30% ; }
#watermark { background: url("../images/watermark2.png") left bottom repeat-x ; background-size: auto 100% ; z-index: -999 ; }
#watermark img { height: 100% ; }
diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js
index f5f9f20..7c5064c 100644
--- a/vasl_templates/webapp/static/main.js
+++ b/vasl_templates/webapp/static/main.js
@@ -1,5 +1,3 @@
-APP_URL_BASE = window.location.origin ;
-
gAppConfig = {} ;
gDefaultTemplatePack = null ;
gTemplatePack = {} ;
@@ -258,6 +256,11 @@ $(document).ready( function () {
$.getJSON( gAppConfigUrl, function(data) {
gAppConfig = data ;
update_page_load_status( "app-config" ) ;
+ var alt_base_url = gAppConfig.ALTERNATE_WEBAPP_BASE_URL ;
+ if ( alt_base_url ) {
+ var $elem = $( "#alt-webapp-base-url" ) ;
+ $elem.text( $elem.text() + " " + alt_base_url ).show() ;
+ }
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the application config:
" + escapeHTML(errorMsg) + "
" ) ;
} ) ;
diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js
index a304015..fbfdbb8 100644
--- a/vasl_templates/webapp/static/snippets.js
+++ b/vasl_templates/webapp/static/snippets.js
@@ -136,7 +136,7 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
params.TIMESTAMP = (new Date()).toISOString() ;
params.IMAGES_BASE_URL = gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET ?
gAppConfig.ONLINE_IMAGES_URL_BASE :
- APP_URL_BASE + gImagesBaseUrl ;
+ make_app_url( gImagesBaseUrl, true ) ;
if ( gUserSettings["snippet-font-family"] ) {
// NOTE: Layout of snippets ends up being slightly different on Windows and Linux, presumably because
// VASSAL is using different fonts. Unfortunately, explicitly specifying which font to use doesn't
@@ -459,8 +459,12 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
}
// fixup any user file URL's
- snippet = strReplaceAll( snippet, "{{USER_FILES}}", APP_URL_BASE+"/user" ) ;
- snippet = strReplaceAll( snippet, "{{CHAPTER_H}}", APP_URL_BASE+"/chapter-h" ) ;
+ snippet = strReplaceAll( snippet, "{{USER_FILES}}",
+ make_app_url( "/user", true )
+ ) ;
+ snippet = strReplaceAll( snippet, "{{CHAPTER_H}}",
+ make_app_url( "/chapter-h", true )
+ ) ;
// tidy up the final snippet
snippet = snippet.replace( /[^\S\r\n]+$/gm, "" ) ; // nb: trim trailing whitespace
@@ -562,7 +566,7 @@ function get_vo_note( vo_type, nat, key )
// FUDGE! We need to detect between a full HTML note and an image-based one.
// This is not great, but it'll do... :-/
if ( vo_note.substr( 0, nat.length+1 ) === nat+"/" )
- return APP_URL_BASE + "/" + vo_type + "/" + nat + "/note/" + key ;
+ return make_app_url( "/" + vo_type + "/" + nat + "/note/" + key, true ) ;
else
return vo_note ;
}
diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js
index 5e2f4d6..8dd70bb 100644
--- a/vasl_templates/webapp/static/utils.js
+++ b/vasl_templates/webapp/static/utils.js
@@ -1,6 +1,15 @@
// --------------------------------------------------------------------
+function make_app_url( url, for_snippet )
+{
+ // generate a URL that accesses this webapp
+ var base_url = window.location.origin ;
+ if ( for_snippet && gAppConfig.ALTERNATE_WEBAPP_BASE_URL )
+ base_url = gAppConfig.ALTERNATE_WEBAPP_BASE_URL ;
+ return base_url + url ;
+}
+
function get_nationality_display_name( nat_id )
{
// get the nationality's display name
@@ -59,7 +68,7 @@ function make_player_flag_url( nat, for_snippet ) {
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ;
else
- return APP_URL_BASE + "/flags/" + nat ;
+ return make_app_url( "/flags/" + nat, for_snippet ) ;
}
function get_player_no_for_element( $elem )
diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js
index bd2ccc2..c0f3d02 100644
--- a/vasl_templates/webapp/static/vo.js
+++ b/vasl_templates/webapp/static/vo.js
@@ -197,7 +197,7 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, elite, custom_cap
var vo_note = get_vo_note( vo_type, nat, vo_note_key ) ;
var vo_note_image_url = null ;
if ( vo_note )
- vo_note_image_url = APP_URL_BASE + "/" + vo_type + "/" + nat + "/note/" + vo_note_key ;
+ vo_note_image_url = make_app_url( "/" + vo_type + "/" + nat + "/note/" + vo_note_key, true ) ;
else {
// NOTE: Note numbers seem to be distinct across all Allied Minor or all Axis Minor vehicles/ordnance,
// so if we don't find a note in a given nationality's normal vehicles/ordnance, we can get away with
@@ -206,7 +206,7 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, elite, custom_cap
if ( ["allied-minor","axis-minor"].indexOf( nat_type ) !== -1 ) {
vo_note = get_vo_note( vo_type, nat_type, vo_note_key ) ;
if ( vo_note )
- vo_note_image_url = APP_URL_BASE + "/" + vo_type + "/" + nat_type + "/note/" + vo_note_key ;
+ vo_note_image_url = make_app_url( "/" + vo_type + "/" + nat_type + "/note/" + vo_note_key, true ) ;
}
}
if ( vo_note ) {
@@ -426,7 +426,7 @@ function get_vo_image_url( vo_entry, vo_image_id, allow_missing_image, for_snipp
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return make_online_counter_image_url( gpid, index ) ;
else
- return make_local_counter_image_url( gpid, index ) ;
+ return make_local_counter_image_url( gpid, index, for_snippet ) ;
}
// couldn't find an image
@@ -439,9 +439,12 @@ function get_vo_image_url( vo_entry, vo_image_id, allow_missing_image, for_snipp
return null ;
}
-function make_local_counter_image_url( gpid, index )
+function make_local_counter_image_url( gpid, index, for_snippet )
{
- url = APP_URL_BASE + "/counter/" + gpid + "/front" ;
+ // generate the image URL for the specified vehicle/ordnance
+ // NOTE: This originally generated a URL that pointed back to the local webapp server,
+ // but this could possibly be changed to another webapp server (hence we need for_snippet).
+ url = make_app_url( "/counter/" + gpid + "/front", for_snippet ) ;
if ( index !== null )
url += "/" + index ;
return url ;
diff --git a/vasl_templates/webapp/templates/counter-image-urls.html b/vasl_templates/webapp/templates/counter-image-urls.html
index b4df76c..65e56c2 100644
--- a/vasl_templates/webapp/templates/counter-image-urls.html
+++ b/vasl_templates/webapp/templates/counter-image-urls.html
@@ -20,7 +20,6 @@ td { border-bottom: 1px solid #eee ; font-size: 90% ; }