def start(self) -> None:
""" When the bus starts, the plugin is also started
and we load the Django application. We then mount it on
the CherryPy engine for serving as a WSGI application.
We let CherryPy serve the application's static files.
"""
from frontend import settings
settings.crawler_settings = self.crawler_settings
os.environ['DJANGO_SETTINGS_MODULE'] = self.settings_module
from django.core.wsgi import get_wsgi_application
def corsstaticdir(
section: str, dir: str, root: str = '', match: str = '',
content_types: None = None, index: str = '', debug: bool = False
) -> bool:
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
return static.staticdir(section, dir, root, match, content_types, index, debug)
cherrypy.tree.graft(self.wsgi_http_logger(get_wsgi_application(), self.crawler_settings))
settings.WORKERS.start_workers(settings.CRAWLER_SETTINGS)
tool = cherrypy._cptools.HandlerTool(corsstaticdir)
static_handler = tool.handler(
section="/",
dir=os.path.split(settings.STATIC_ROOT)[1],
root=os.path.abspath(os.path.split(settings.STATIC_ROOT)[0])
)
cherrypy.tree.mount(static_handler, settings.STATIC_URL)
media_handler = tool.handler(
section="/",
dir=os.path.split(settings.MEDIA_ROOT)[1],
root=os.path.abspath(os.path.split(settings.MEDIA_ROOT)[0])
)
cherrypy.tree.mount(media_handler, settings.MEDIA_URL)
评论列表
文章目录