static file handling fix
This commit is contained in:
parent
a02a9081f8
commit
71d3bd85cc
@ -36,6 +36,10 @@ if __name__ == "__main__":
|
|||||||
runwsgi_parser = subparsers.add_parser(
|
runwsgi_parser = subparsers.add_parser(
|
||||||
'runwsgi', help='run WSGI application'
|
'runwsgi', help='run WSGI application'
|
||||||
)
|
)
|
||||||
|
runwsgi_parser.add_argument(
|
||||||
|
'-p', '--port', dest='port', action='store', type=str,
|
||||||
|
help='application port', default='8000'
|
||||||
|
)
|
||||||
test_parser = subparsers.add_parser(
|
test_parser = subparsers.add_parser(
|
||||||
'test', help='run unit tests'
|
'test', help='run unit tests'
|
||||||
)
|
)
|
||||||
@ -86,7 +90,7 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
logging.info("Running WSGI app...")
|
logging.info("Running WSGI app...")
|
||||||
server = web.httpserver.WSGIServer(
|
server = web.httpserver.WSGIServer(
|
||||||
("0.0.0.0", 8080),
|
("0.0.0.0", int(params.port)),
|
||||||
app.wsgifunc()
|
app.wsgifunc()
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
@ -5,5 +5,5 @@ from webui.urls import webui_app
|
|||||||
|
|
||||||
urls = (
|
urls = (
|
||||||
"/api", api_app,
|
"/api", api_app,
|
||||||
"/", webui_app
|
"", webui_app
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import web
|
import web
|
||||||
|
import mimetypes
|
||||||
|
import posixpath
|
||||||
from settings import settings
|
from settings import settings
|
||||||
|
|
||||||
render = web.template.render(settings.TEMPLATE_DIR)
|
render = web.template.render(settings.TEMPLATE_DIR)
|
||||||
@ -9,3 +11,16 @@ render = web.template.render(settings.TEMPLATE_DIR)
|
|||||||
class IndexHandler(object):
|
class IndexHandler(object):
|
||||||
def GET(self):
|
def GET(self):
|
||||||
return render.index()
|
return render.index()
|
||||||
|
|
||||||
|
|
||||||
|
class StaticHandler(object):
|
||||||
|
def GET(self, fl):
|
||||||
|
fl_path = posixpath.join(settings.STATIC_DIR, fl)
|
||||||
|
mimetype = mimetypes.guess_type(fl_path)[0]
|
||||||
|
if mimetype:
|
||||||
|
web.header("Content-Type", mimetype)
|
||||||
|
try:
|
||||||
|
f = open(fl_path, 'r')
|
||||||
|
return f.read()
|
||||||
|
except:
|
||||||
|
raise web.notfound()
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import web
|
import web
|
||||||
|
|
||||||
from webui.handlers import IndexHandler
|
from webui.handlers import IndexHandler, StaticHandler
|
||||||
|
|
||||||
urls = (
|
urls = (
|
||||||
r"", 'IndexHandler',
|
r"/static/(.*)", 'StaticHandler',
|
||||||
|
r"/", 'IndexHandler',
|
||||||
)
|
)
|
||||||
|
|
||||||
webui_app = web.application(urls, locals())
|
webui_app = web.application(urls, locals())
|
||||||
|
Loading…
Reference in New Issue
Block a user