Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit 773d629

Browse files
Fix routing for custom bottles
PR #203 added the ability for users to pass a custom Bottle instance to Eel, which was intended to help them add middleware. Unfortunately, the custom app instance has no routing set up and so fundamentally fails to support Eel's functionality. This patch applies the functions that handle routing to any custom bottles before handing off off to bottle to run the server. Fix #211
1 parent f42ca61 commit 773d629

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

eel/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ def run_lambda():
138138
HOST = '0.0.0.0'
139139
else:
140140
HOST = _start_args['host']
141+
142+
app = _start_args.get('app', btl.default_app) # type: btl.Bottle
143+
for route_path, route_params in BOTTLE_ROUTES.items():
144+
route_func, route_kwargs = route_params
145+
app.route(path=route_path, callback=route_func, **route_kwargs)
146+
141147
return btl.run(
142148
host=HOST,
143149
port=_start_args['port'],
144150
server=wbs.GeventWebSocketServer,
145151
quiet=True,
146-
app=_start_args.get('app'))
152+
app=app)
147153

148154
# Start the webserver
149155
if _start_args['block']:
@@ -165,7 +171,6 @@ def spawn(function, *args, **kwargs):
165171

166172
# Bottle Routes
167173

168-
@btl.route('/eel.js')
169174
def _eel():
170175
start_geometry = {'default': {'size': _start_args['size'],
171176
'position': _start_args['position']},
@@ -179,8 +184,6 @@ def _eel():
179184
_set_response_headers(btl.response)
180185
return page
181186

182-
183-
@btl.route('/<path:path>')
184187
def _static(path):
185188
response = None
186189
if 'jinja_env' in _start_args and 'jinja_templates' in _start_args:
@@ -196,8 +199,6 @@ def _static(path):
196199
_set_response_headers(response)
197200
return response
198201

199-
200-
@btl.get('/eel', apply=[wbs.websocket])
201202
def _websocket(ws):
202203
global _websockets
203204

@@ -223,6 +224,13 @@ def _websocket(ws):
223224

224225
_websocket_close(page)
225226

227+
228+
BOTTLE_ROUTES = {
229+
"/eel.js": (_eel, dict()),
230+
"/<path:path>": (_static, dict()),
231+
"/eel": (_websocket, dict(apply=[wbs.websocket]))
232+
}
233+
226234
# Private functions
227235

228236
def _safe_json(obj):

0 commit comments

Comments
 (0)