60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
# from waitress import serve
|
|
# from flask import Flask, request, jsonify
|
|
import uvicorn
|
|
from fastapi import FastAPI, Request, HTTPException, status
|
|
from dotenv import load_dotenv
|
|
import logging
|
|
import time
|
|
|
|
app = FastAPI()
|
|
|
|
@app.get('/')
|
|
async def root():
|
|
return {'message': 'Welcome to Gitea Runner'}
|
|
|
|
@app.post('/test')
|
|
async def test(request: Request):
|
|
""" Test connection to server. """
|
|
logging.debug('Content-Type: ', request.headers.get('content-type'))
|
|
return {'status': 'success'}
|
|
|
|
@app.post('/event')
|
|
def handle_event(request: Request):
|
|
"""
|
|
Handle event from webhook
|
|
"""
|
|
time.sleep(10)
|
|
return {'status': 'success'}
|
|
|
|
# @app.post('/execute')
|
|
|
|
# @app.before_request
|
|
# def check_media_type():
|
|
# """
|
|
# Ignore requests that do not have Content-Type = application/json in header.
|
|
# """
|
|
# content_type = request.headers.get('Content-Type')
|
|
# if content_type is None or not content_type.lower().startswith('application/json'):
|
|
# logging.error(
|
|
# f"request with wrong content type made by {request.remote_addr}"
|
|
# )
|
|
# return jsonify(status='unsupported media type'), 415
|
|
|
|
# @app.route('/test', methods=['POST'])
|
|
# def test():
|
|
# logging.debug('Content-Type: ' + request.headers.get('Content-Type'))
|
|
# logging.debug(request.get_json(force=True))
|
|
# return jsonify(status='success', sender=request.remote_addr), 200
|
|
|
|
if __name__ == '__main__':
|
|
load_dotenv()
|
|
# prepare variables
|
|
# serve(
|
|
# app=app,
|
|
# host=listen_ip,
|
|
# port=listen_port
|
|
# )
|
|
uvicorn.run(
|
|
app=app,
|
|
host='0.0.0.0'
|
|
) |