mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-23 23:17:58 +00:00
fix running via pyinstaller bin
This commit is contained in:
parent
c3b4d9ca98
commit
1eb93ab71a
11
relay.spec
11
relay.spec
|
@ -1,7 +1,10 @@
|
||||||
# -*- mode: python ; coding: utf-8 -*-
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
import importlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
block_cipher = None
|
block_cipher = None
|
||||||
|
aiohttp_swagger_path = Path(importlib.import_module('aiohttp_swagger').__file__).parent
|
||||||
|
|
||||||
|
|
||||||
a = Analysis(
|
a = Analysis(
|
||||||
|
@ -9,9 +12,13 @@ a = Analysis(
|
||||||
pathex=[],
|
pathex=[],
|
||||||
binaries=[],
|
binaries=[],
|
||||||
datas=[
|
datas=[
|
||||||
('relay/data', 'relay/data')
|
('relay/data', 'relay/data'),
|
||||||
|
(aiohttp_swagger_path, 'aiohttp_swagger')
|
||||||
|
],
|
||||||
|
hiddenimports=[
|
||||||
|
'gunicorn',
|
||||||
|
'gunicorn.glogging'
|
||||||
],
|
],
|
||||||
hiddenimports=[],
|
|
||||||
hookspath=[],
|
hookspath=[],
|
||||||
hooksconfig={},
|
hooksconfig={},
|
||||||
runtime_hooks=[],
|
runtime_hooks=[],
|
||||||
|
|
|
@ -4,9 +4,12 @@ import Crypto
|
||||||
import asyncio
|
import asyncio
|
||||||
import click
|
import click
|
||||||
import platform
|
import platform
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from aputils.signer import Signer
|
from aputils.signer import Signer
|
||||||
|
from gunicorn.app.wsgiapp import WSGIApplication
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
@ -234,9 +237,21 @@ def cli_run(ctx: click.Context, dev: bool = False) -> None:
|
||||||
click.echo(pip_command)
|
click.echo(pip_command)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
subprocess.run([sys.executable, 'run-gunicorn'], check = False)
|
||||||
|
return
|
||||||
|
|
||||||
ctx.obj.run(dev)
|
ctx.obj.run(dev)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command('run-gunicorn')
|
||||||
|
@click.pass_context
|
||||||
|
def cli_run_gunicorn(ctx: click.Context) -> None:
|
||||||
|
runner = GunicornRunner(ctx.obj)
|
||||||
|
runner.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command('convert')
|
@cli.command('convert')
|
||||||
@click.option('--old-config', '-o', help = 'Path to the config file to convert from')
|
@click.option('--old-config', '-o', help = 'Path to the config file to convert from')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
|
@ -903,6 +918,31 @@ def cli_whitelist_import(ctx: click.Context) -> None:
|
||||||
click.echo('Imported whitelist from inboxes')
|
click.echo('Imported whitelist from inboxes')
|
||||||
|
|
||||||
|
|
||||||
|
class GunicornRunner(WSGIApplication):
|
||||||
|
def __init__(self, app: Application):
|
||||||
|
self.app = app
|
||||||
|
self.app_uri = 'relay.application:main_gunicorn'
|
||||||
|
self.options = {
|
||||||
|
'bind': f'{app.config.listen}:{app.config.port}',
|
||||||
|
'worker_class': 'aiohttp.GunicornWebWorker',
|
||||||
|
'workers': app.config.workers,
|
||||||
|
'raw_env': f'CONFIG_FILE={app.config.path}'
|
||||||
|
}
|
||||||
|
|
||||||
|
WSGIApplication.__init__(self)
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
for key, value in self.options.items():
|
||||||
|
self.cfg.set(key, value)
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
logging.info('Starting webserver for %s', self.app.config.domain)
|
||||||
|
WSGIApplication.run(self)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
# pylint: disable=no-value-for-parameter
|
# pylint: disable=no-value-for-parameter
|
||||||
cli(prog_name='relay')
|
cli(prog_name='relay')
|
||||||
|
|
|
@ -42,8 +42,6 @@ def check_api_path(method: str, path: str) -> bool:
|
||||||
|
|
||||||
@web.middleware
|
@web.middleware
|
||||||
async def handle_api_path(request: web.Request, handler: Coroutine) -> web.Response:
|
async def handle_api_path(request: web.Request, handler: Coroutine) -> web.Response:
|
||||||
print("Authorization:", request.headers.get('Authorization'))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request['token'] = request.headers['Authorization'].replace('Bearer', '').strip()
|
request['token'] = request.headers['Authorization'].replace('Bearer', '').strip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue