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

Commit ee87dd2

Browse files
Merge pull request #212 from samuelhwilliams/fix-211
Fix routing for custom bottles
2 parents 5f62b06 + c644227 commit ee87dd2

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change log
22

3+
### v0.11.1
4+
* Fix the implementation of #203, allowing users to pass their own bottle instances into Eel.
5+
36
### v0.11.0
47
* Added support for `app` parameter to `eel.start`, which will override the bottle app instance used to run eel. This
58
allows developers to apply any middleware they wish to before handing over to eel.

eel/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'app_mode': True, # (Chrome specific option)
4141
'all_interfaces': False, # Allow bottle server to listen for connections on all interfaces
4242
'disable_cache': True, # Sets the no-store response header when serving assets
43-
'app': None, # Allows passing in a custom Bottle instance, e.g. with middleware
43+
'app': btl.default_app(), # Allows passing in a custom Bottle instance, e.g. with middleware
4444
}
4545

4646
# == Temporary (suppressable) error message to inform users of breaking API change for v1.0.0 ===
@@ -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['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):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='Eel',
9-
version='0.11.0',
9+
version='0.11.1',
1010
author='Chris Knott',
1111
author_email='chrisknott@hotmail.co.uk',
1212
url='https://github.com/samuelhwilliams/Eel',

0 commit comments

Comments
 (0)