Skip to content

Commit 43182ff

Browse files
committed
Add sanity checks to example server
1 parent 503b956 commit 43182ff

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

example/server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
http://localhost:8888/ to view the index.html page.
88
'''
99

10-
from os.path import abspath, dirname, join
10+
from os.path import abspath, dirname, exists, join
1111
from optparse import OptionParser
1212

1313
import tornado.web
@@ -57,10 +57,18 @@ def init_networktables(ipaddr):
5757

5858
# setup tornado application with static handler + networktables support
5959
www_dir = abspath(join(dirname(__file__), 'www'))
60+
index_html = join(www_dir, 'index.html')
61+
62+
if not exists(www_dir):
63+
logger.error("Directory '%s' does not exist!" % www_dir)
64+
exit(1)
65+
66+
if not exists(index_html):
67+
logger.warn("%s not found" % index_html)
6068

6169
app = tornado.web.Application(
6270
get_handlers() + [
63-
(r"/()", NonCachingStaticFileHandler, {"path": join(www_dir, 'index.html')}),
71+
(r"/()", NonCachingStaticFileHandler, {"path": index_html}),
6472
(r"/(.*)", NonCachingStaticFileHandler, {"path": www_dir})
6573
]
6674
)

0 commit comments

Comments
 (0)