Created
July 5, 2023 11:03
-
-
Save trohit/2426c38431a7d68d848a041f9deee11e to your computer and use it in GitHub Desktop.
HTTPS + FastAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.7 | |
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get('/') | |
async def home(): | |
return {"msg":"hi"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#import uvicorn | |
#from uvicorn.config import LOGGING_CONFIG | |
# Importing app here makes the syntax cleaner as it will be picked up by refactors | |
import os,sys | |
file_dir = os.path.dirname(__file__) | |
sys.path.append(file_dir) | |
from main import app | |
from fastapi import FastAPI | |
from hypercorn.config import Config | |
from hypercorn.asyncio import serve | |
import hypercorn.logging | |
import asyncio | |
import logging | |
import time | |
import datetime | |
import pytz | |
import ssl | |
import sys | |
""" | |
cert_path = "./cert.pem" | |
key_path = "./key.pem" | |
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | |
ssl_context.load_cert_chain(cert_path, key_path) | |
""" | |
if __name__ == "__main__": | |
argc = len(sys.argv) | |
arg_port = 8000 | |
if argc > 1: | |
arg_port = sys.argv[1] | |
print(f"using port {arg_port}") | |
config = Config() | |
config.bind = ["0.0.0.0:" + arg_port] # Set the address and port to bind to | |
#config.bind = ["0.0.0.0:443"] # Set the address and port to bind to | |
config.certfile = "./cert.pem" # Set the path to your SSL certificate file | |
config.keyfile = "./key.pem" # Set the path to your SSL private key file | |
config.accesslog = "./hyper.log" | |
config.errorlog = "./err.log" | |
config.loglevel = "debug" | |
config.use_reloader = True | |
asyncio.run(serve(app, config)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment