Skip to content

Commit 7211e8b

Browse files
author
Norman Young
committed
Check RootPath to avoid failure with typical MicroPython /flash/www
1 parent 4acd5be commit 7211e8b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

MicroWebSrv2/libs/XAsyncSockets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import sys
77
_IS_MICROPYTHON = sys.implementation.name == 'micropython'
8+
_IS_MICROPYTHON_LINUX = _IS_MICROPYTHON and (sys.platform == 'linux')
89

910
from _thread import allocate_lock, start_new_thread
1011
from time import sleep
@@ -439,7 +440,7 @@ def __init__(self, asyncSocketsPool, srvSocket, srvAddr, bufSlots) :
439440
def OnReadyForReading(self) :
440441
try :
441442
cliSocket, cliAddr = self._socket.accept()
442-
if _IS_MICROPYTHON:
443+
if _IS_MICROPYTHON_LINUX: # TODO Resolve ports/unix dependency
443444
# b'\x02\x00\x89L\x7f\x00\x00\x01'
444445
address = ".".join([str(byte[0])
445446
for byte in struct.unpack('ssss', cliAddr[4:8])])

main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,16 @@ def OnWSChatClosed(webSocket) :
163163
# For embedded MicroPython, use a very light configuration,
164164
mws2.SetEmbeddedConfig()
165165

166-
# All pages not found will be redirected to the home '/',
167-
mws2.NotFoundURL = '/'
166+
# mws2.RootPath = '/flash/www' # E.g., MicroPython
167+
# Confirm that RootPath will resolve for home URL
168+
HOME = '/'
169+
if not mws2.ResolvePhysicalPath(HOME):
170+
raise MicroWebSrv2Exception(
171+
"RootPath '%s' does not resolve with URL '%s'" % (mws2.RootPath, HOME)
172+
)
173+
174+
# All pages not found will be redirected to the home,
175+
mws2.NotFoundURL = HOME
168176

169177
# Starts the server as easily as possible in managed mode,
170178
mws2.StartManaged()

0 commit comments

Comments
 (0)