generated from jCloud/repository-template
Divide API into modules
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
# Copyright 2026 jCloud
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from fastapi import FastAPI
|
||||
import os
|
||||
import uvicorn
|
||||
import ipaddress
|
||||
import jcloud_config_parser
|
||||
import logging
|
||||
from .arguments import parse_args
|
||||
from .config import load_config, process_host_and_port
|
||||
from .logging import setup_logging
|
||||
from ..integrations.gitea.middlewares.signature import GiteaSignatureMiddleware
|
||||
import sys
|
||||
|
||||
def main():
|
||||
args = parse_args(sys.argv[1:])
|
||||
|
||||
configuration, default_configuration = load_config(args.config)
|
||||
|
||||
logger_info = setup_logging(configuration)
|
||||
|
||||
host, port = process_host_and_port(
|
||||
configuration,
|
||||
default_configuration,
|
||||
args,
|
||||
logger_info.logger
|
||||
)
|
||||
|
||||
# Initialize FastAPI
|
||||
app = FastAPI(
|
||||
docs_url=configuration.docs.swagger,
|
||||
redoc_url=configuration.docs.redoc,
|
||||
openapi_url=configuration.docs.openapi
|
||||
)
|
||||
|
||||
app.add_middleware(GiteaSignatureMiddleware, secret = b'', logger = logger_info.logger)
|
||||
|
||||
uvicorn.run(
|
||||
app,
|
||||
host = host,
|
||||
port = port,
|
||||
server_header = False,
|
||||
log_config = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
'handlers': {
|
||||
'uvicorn_handler': {
|
||||
'class': 'logging.FileHandler',
|
||||
'filename': str(logger_info.logfile),
|
||||
'formatter': 'uvicorn_formatter',
|
||||
},
|
||||
},
|
||||
'formatters': {
|
||||
'uvicorn_formatter': {
|
||||
'format': logger_info.format
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'uvicorn': {
|
||||
'handlers': ['uvicorn_handler'],
|
||||
'level': logger_info.level,
|
||||
'propagate': False
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user