ahserver_g/ahserver/configuredServer.py

63 lines
1.8 KiB
Python
Raw Normal View History

2019-07-10 17:34:45 +08:00
import os,sys
2021-06-24 11:01:37 +08:00
import time
2019-07-10 17:34:45 +08:00
import ssl
2021-05-17 10:58:51 +08:00
from socket import *
2019-07-10 17:34:45 +08:00
from aiohttp import web
from appPublic.folderUtils import ProgramPath
2021-05-17 10:58:51 +08:00
from appPublic.background import Background
2019-07-10 17:34:45 +08:00
from appPublic.jsonConfig import getConfig
2022-06-23 14:58:03 +08:00
from appPublic.app_logger import AppLogger
2019-07-10 17:34:45 +08:00
from sqlor.dbpools import DBPools
from .processorResource import ProcessorResource
from .auth_api import AuthAPI
from .myTE import setupTemplateEngine
from .globalEnv import initEnv
2023-02-22 23:37:09 +08:00
from .filestorage import TmpFileRecord
2019-07-10 17:34:45 +08:00
2022-06-23 14:58:03 +08:00
class ConfiguredServer(AppLogger):
2022-05-20 17:53:06 +08:00
def __init__(self, auth_klass=AuthAPI, workdir=None):
2022-06-23 14:58:03 +08:00
super().__init__()
2022-06-23 15:33:34 +08:00
if workdir is not None:
pp = ProgramPath()
config = getConfig(workdir,{'workdir':workdir,'ProgramPath':pp})
else:
config = getConfig()
2019-07-10 17:34:45 +08:00
if config.databases:
DBPools(config.databases)
initEnv()
setupTemplateEngine()
2023-05-29 15:35:03 +08:00
client_max_size = 1024 * 10240
2023-05-29 20:26:06 +08:00
if config.website.client_max_size:
client_max_size = config.website.client_max_size
2023-05-29 20:35:23 +08:00
print(f'{client_max_size=}')
2023-05-29 15:35:03 +08:00
self.app = web.Application(client_max_size=client_max_size)
2019-07-10 18:42:54 +08:00
auth = auth_klass()
2019-07-10 17:34:45 +08:00
auth.setupAuth(self.app)
self.configPath(config)
def run(self):
2023-02-22 23:37:09 +08:00
a = TmpFileRecord()
2019-07-10 17:34:45 +08:00
config = getConfig()
ssl_context = None
if config.website.ssl:
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain(config.website.ssl.crtfile,
config.website.ssl.keyfile)
2021-05-17 10:58:51 +08:00
2019-07-10 17:34:45 +08:00
web.run_app(self.app,host=config.website.host or '0.0.0.0',
port=config.website.port or 8080,
ssl_context=ssl_context)
def configPath(self,config):
for p,prefix in config.website.paths:
res = ProcessorResource(prefix,p,show_index=True,
2019-12-03 11:30:15 +08:00
follow_symlinks=True,
2019-12-05 06:04:38 +08:00
indexes=config.website.indexes,
processors=config.website.processors)
2019-07-10 17:34:45 +08:00
self.app.router.register_resource(res)