mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #1178 from robulouski/devserver_fix
Fix issue in devserver introduced in v3.3
This commit is contained in:
commit
e58cab0250
1 changed files with 10 additions and 7 deletions
|
|
@ -13,23 +13,26 @@ except ImportError:
|
||||||
import socketserver # NOQA
|
import socketserver # NOQA
|
||||||
|
|
||||||
PORT = len(sys.argv) == 2 and int(sys.argv[1]) or 8000
|
PORT = len(sys.argv) == 2 and int(sys.argv[1]) or 8000
|
||||||
SUFFIXES = ['','.html','/index.html']
|
SUFFIXES = ['', '.html', '/index.html']
|
||||||
|
|
||||||
|
|
||||||
class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):
|
class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
# we are trying to detect the file by having a fallback mechanism
|
# we are trying to detect the file by having a fallback mechanism
|
||||||
r = None
|
found = False
|
||||||
for suffix in SUFFIXES:
|
for suffix in SUFFIXES:
|
||||||
if not hasattr(self,'original_path'):
|
if not hasattr(self,'original_path'):
|
||||||
self.original_path = self.path
|
self.original_path = self.path
|
||||||
self.path = self.original_path + suffix
|
self.path = self.original_path + suffix
|
||||||
path = self.translate_path(self.path)
|
path = self.translate_path(self.path)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
r = srvmod.SimpleHTTPRequestHandler.do_GET(self)
|
srvmod.SimpleHTTPRequestHandler.do_GET(self)
|
||||||
if r is not None:
|
logging.info("Found: %s" % self.path)
|
||||||
|
found = True
|
||||||
break
|
break
|
||||||
logging.warning("Unable to find %s file." % self.path)
|
logging.info("Tried to find file %s, but it doesn't exist. " % self.path)
|
||||||
return r
|
if not found:
|
||||||
|
logging.warning("Unable to find file %s or variations." % self.path)
|
||||||
|
|
||||||
Handler = ComplexHTTPRequestHandler
|
Handler = ComplexHTTPRequestHandler
|
||||||
|
|
||||||
|
|
@ -45,4 +48,4 @@ try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
logging.info("shutting down server")
|
logging.info("shutting down server")
|
||||||
httpd.socket.close()
|
httpd.socket.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue