Skip to content

Commit

Permalink
Fix #6055 default to tornado api_server in dev mode (#6072)
Browse files Browse the repository at this point in the history
* Fix #6055 default to tornado api_server in dev mode

* Fix #6074 remove google_tag_manager

---------

Co-authored-by: Raven <ravenmarieorourke@gmail.com>
  • Loading branch information
Rob Nagler and rorour authored Jul 5, 2023
1 parent 75ec5d8 commit d2ec801
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 70 deletions.
2 changes: 1 addition & 1 deletion sirepo/pkcli/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _cfg():
# so limit to 128, which is probably more than enough with
# this application.
threads=(10, _cfg_int(1, 128), "how many uwsgi threads in each process"),
tornado=(False, bool, "use tornado for server"),
tornado=(pkconfig.in_dev_mode(), bool, "use tornado for server"),
use_reloader=(pkconfig.in_dev_mode(), bool, "use the server reloader"),
)
return __cfg
Expand Down
23 changes: 0 additions & 23 deletions sirepo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
):
import h5py

#: If google_tag_manager_id set, string to insert in landing pages for google analytics
_google_tag_manager = None

#: what to match in landing pages to insert `_google_tag_manager`
_google_tag_manager_re = re.compile("(?=</head>)", flags=re.IGNORECASE)

_ROBOTS_TXT = None

#: Global app value (only here so instance not lost)
Expand Down Expand Up @@ -624,16 +618,6 @@ async def api_staticFile(self, path_info=None):
raise sirepo.util.NotFound("empty path info")
self._proxy_react(f"{sirepo.const.STATIC_D}/" + path_info)
p = sirepo.resource.static(sirepo.util.validate_path(path_info))
if _google_tag_manager and re.match(r"^en/[^/]+html$", path_info):
return self.headers_for_cache(
self.reply(
content=_google_tag_manager_re.sub(
_google_tag_manager,
pkio.read_text(p),
),
),
path=p,
)
if re.match(r"^(html|en)/[^/]+html$", path_info):
return self.reply_html(p)
return self.reply_file(p)
Expand Down Expand Up @@ -816,17 +800,11 @@ def init_app(uwsgi=None, use_reloader=False, is_server=False):
sirepo.modules.import_and_init("sirepo.uri_router").init_for_flask(_app)
sirepo.flask.app_set(_app)
if is_server:
global _google_tag_manager
from sirepo import auth_db

with sirepo.quest.start() as qcall:
qcall.auth_db.create_or_upgrade()

if _cfg.google_tag_manager_id:
_google_tag_manager = f"""<script>
(function(w,d,s,l,i){{w[l]=w[l]||[];w[l].push({{'gtm.start':new Date().getTime(),event:'gtm.js'}});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);}})(window,document,'script','dataLayer','{_cfg.google_tag_manager_id}');
</script>"""

# Avoid unnecessary logging
sirepo.flask.is_server = True
return _app
Expand Down Expand Up @@ -920,7 +898,6 @@ def _source_cache_key():
bool,
"enable source cache key, disable to allow local file edits in Chrome",
),
google_tag_manager_id=(None, str, "enable google analytics with this id"),
home_page_uri=("/en/landing.html", str, "home page to redirect to"),
react_server=(
None if pkconfig.in_dev_mode() else _REACT_SERVER_BUILD,
Expand Down
40 changes: 0 additions & 40 deletions tests/google_tag_manager_test.py

This file was deleted.

6 changes: 0 additions & 6 deletions tests/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def test_myapp_basic(fc):

r = fc.sr_get("/robots.txt")
pkunit.pkre("elegant.*myapp.*srw", pkcompat.from_bytes(r.data))
r = fc.sr_get("/")
pkok(
not re.search(r"googletag", pkcompat.from_bytes(r.data)),
"Unexpected injection of googletag data={}",
r.data,
)


def test_srw(fc):
Expand Down

0 comments on commit d2ec801

Please sign in to comment.