53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from __future__ import unicode_literals
|
|
import gunicorn.app.base
|
|
import getpass
|
|
import os
|
|
import webob.static
|
|
import logging
|
|
|
|
|
|
config = os.path.join(os.path.dirname(__file__), 'development.ini')
|
|
|
|
|
|
class DebugApplication(object):
|
|
|
|
def __init__(self, app, staticpath='.'):
|
|
self.app = app
|
|
self.static = webob.static.DirectoryApp(os.path.realpath(staticpath))
|
|
|
|
def __call__(self, environ, start_response):
|
|
path_info = environ['PATH_INFO'].lstrip('/')
|
|
if path_info and os.path.exists(self.static.path + path_info):
|
|
return self.static(environ, start_response)
|
|
else:
|
|
return self.app(environ, start_response)
|
|
|
|
|
|
class Server(gunicorn.app.base.Application):
|
|
|
|
ACCESS_LOG_FORMAT = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s"'
|
|
|
|
def init(self, parser, opts, args):
|
|
pass
|
|
|
|
def load_default_config(self):
|
|
super(Server, self).load_default_config()
|
|
self.cfg.set('bind', '[::]:8080')
|
|
self.cfg.set('reload', True)
|
|
self.cfg.set('workers', 1)
|
|
self.cfg.set('threads', 1)
|
|
self.cfg.set('accesslog', '-')
|
|
self.cfg.set('access_log_format', self.ACCESS_LOG_FORMAT)
|
|
self.cfg.set('timeout', 9001)
|
|
self.cfg.set('errorlog', '-')
|
|
|
|
def load(self):
|
|
import dcow.app
|
|
app = dcow.app.Application.create(config)
|
|
return DebugApplication(app)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
Server().run()
|