Skip to content

Commit

Permalink
Check RootPath to avoid failure with typical MicroPython /flash/www
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Young committed Sep 20, 2020
1 parent d465ef2 commit e56ac02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion MicroWebSrv2/libs/XAsyncSockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
_IS_MICROPYTHON = sys.implementation.name == 'micropython'
_IS_MICROPYTHON_LINUX = _IS_MICROPYTHON and (sys.platform == 'linux')

from _thread import allocate_lock, start_new_thread
from time import sleep
Expand Down Expand Up @@ -439,7 +440,7 @@ def __init__(self, asyncSocketsPool, srvSocket, srvAddr, bufSlots) :
def OnReadyForReading(self) :
try :
cliSocket, cliAddr = self._socket.accept()
if _IS_MICROPYTHON:
if _IS_MICROPYTHON_LINUX: # TODO Resolve ports/unix dependency
# b'\x02\x00\x89L\x7f\x00\x00\x01'
address = ".".join([str(byte[0])
for byte in struct.unpack('ssss', cliAddr[4:8])])
Expand Down
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ def OnWSChatClosed(webSocket) :
# For embedded MicroPython, use a very light configuration,
mws2.SetEmbeddedConfig()

# All pages not found will be redirected to the home '/',
mws2.NotFoundURL = '/'
# mws2.RootPath = '/flash/www' # E.g., MicroPython
# Confirm that RootPath will resolve for home URL
HOME = '/'
if not mws2.ResolvePhysicalPath(HOME):
raise MicroWebSrv2Exception(
"RootPath '%s' does not resolve with URL '%s'" % (mws2.RootPath, HOME)
)

# All pages not found will be redirected to the home,
mws2.NotFoundURL = HOME

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

0 comments on commit e56ac02

Please sign in to comment.