Skip to content
/ OJ-Be Public
forked from zcluu/OJ-Be

OnlineJudge Backend With FastAPI

License

Notifications You must be signed in to change notification settings

GCLion/OJ-Be

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pre work

Ensure support for Python

sudo apt update
sudo apt install python3.8

check Python3 is available

python3.8 --version

Initialize environment

python3 -m venv your_venv_name
source your_venv_name/bin/activate

Run this application as a package

pip3 install -e .
from OJ import OJBe

server = OJBe(host, port, no_cors)  # server-host,server-port,no-cors required
server.start()

Visit the OJ-Be api page

Use your browser to open http://127.0.0.1:8000/docs

Customize exclusive features

In main.py we provide three parameters, namely host/port/no-cors. You can use command-line parameters to modify host and port during startup.

python3 main.py --host 0.0.0.0 --port 16808 --no_cors

If use no-cors, the frontend and the backend must be in the same domain.

In the OJ package, we only provide basic functions. We also provide an open interface to add custom functions.

For example, you can customize a new route function named CFunction using APIRouter. Then you can add route using server.add_route(CFunction).

...
server = OJBe()
server.add_route(CFunction)
...

You can also use BaseHTTPMiddleware to customize middleware.

class YourMiddleware(BaseHTTPMiddleware):
    def __init__(self):
        ...

    async def dispatch(self, request: Request, call_next: RequestResponseEndpoint):
        ...


...
server = OJBe()
server.add_middleware(YourMiddleware)
...

About

OnlineJudge Backend With FastAPI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%