This repository was archived by the owner on Jun 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +55
-3
lines changed
examples/10 - custom_app_routes Expand file tree Collapse file tree 4 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -169,9 +169,11 @@ def run_lambda():
169169 HOST = _start_args ['host' ]
170170
171171 app = _start_args ['app' ] # type: btl.Bottle
172- for route_path , route_params in BOTTLE_ROUTES .items ():
173- route_func , route_kwargs = route_params
174- btl .route (path = route_path , callback = route_func , ** route_kwargs )
172+
173+ if isinstance (app , btl .Bottle ):
174+ add_eel_routes (app )
175+ else :
176+ add_eel_routes (btl .default_app ())
175177
176178 return btl .run (
177179 host = HOST ,
@@ -264,6 +266,19 @@ def _websocket(ws):
264266 "/eel" : (_websocket , dict (apply = [wbs .websocket ]))
265267}
266268
269+ def add_eel_routes (app ):
270+ '''
271+ Adds eel routes to `app`. Only needed if you are passing something besides `bottle.Bottle` to `eel.start()`.
272+ Ex:
273+ app = bottle.Bottle()
274+ eel.add_eel_routes(app)
275+ middleware = beaker.middleware.SessionMiddleware(app)
276+ eel.start(app=middleware)
277+ '''
278+ for route_path , route_params in BOTTLE_ROUTES .items ():
279+ route_func , route_kwargs = route_params
280+ app .route (path = route_path , callback = route_func , ** route_kwargs )
281+
267282# Private functions
268283
269284def _safe_json (obj ):
Original file line number Diff line number Diff line change 1+ import eel
2+ import bottle
3+ from beaker .middleware import SessionMiddleware
4+
5+ app = bottle .Bottle ()
6+ @app .route ('/custom' )
7+ def custom_route ():
8+ return 'Hello, World!'
9+
10+ # need to manually add eel routes if we are wrapping our Bottle instance with middleware
11+ eel .add_eel_routes (app )
12+ middleware = SessionMiddleware (app )
13+
14+ eel .init ('web' )
15+ eel .start ('index.html' , app = middleware )
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+
4+ < head >
5+ < title > Hello, World!</ title >
6+ </ head >
7+
8+ </ html >
Original file line number Diff line number Diff line change @@ -61,3 +61,17 @@ def test_06_jinja_templates(driver: webdriver.Remote):
6161
6262 driver .find_element_by_css_selector ('a' ).click ()
6363 WebDriverWait (driver , 2.0 ).until (expected_conditions .presence_of_element_located ((By .XPATH , '//h1[text()="This is page 2"]' )))
64+
65+
66+ def test_10_custom_app (driver : webdriver .Remote ):
67+ # test default eel routes are working
68+ with get_eel_server ('examples/10 - custom_app_routes/custom_app.py' , 'index.html' ) as eel_url :
69+ driver .get (eel_url )
70+ # we really need to test if the page 404s, but selenium has no support for status codes
71+ # so we just test if we can get our page title
72+ assert driver .title == 'Hello, World!'
73+
74+ # test default eel routes are working
75+ with get_eel_server ('examples/10 - custom_app_routes/custom_app.py' , 'custom' ) as eel_url :
76+ driver .get (eel_url )
77+ assert 'Hello, World!' in driver .page_source
You can’t perform that action at this time.
0 commit comments