mirror of
https://codeberg.org/gothub/RandomInstance
synced 2024-12-06 19:16:49 +01:00
@@ -0,0 +1 @@
|
||||
__pycache__/
|
||||
+6
-11
@@ -1,16 +1,11 @@
|
||||
# pull down the pode image
|
||||
FROM badgerati/pode:latest-alpine
|
||||
FROM python:3.9
|
||||
|
||||
# or use the following for GitHub
|
||||
# FROM docker.pkg.github.com/badgerati/pode/pode:latest-alpine
|
||||
WORKDIR /code
|
||||
|
||||
# copy over the local files to the container
|
||||
COPY . /usr/src/app/
|
||||
COPY ./requirements.txt /code/requirements.txt
|
||||
|
||||
# expose the port
|
||||
EXPOSE 8080
|
||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
||||
|
||||
ENV DOCKER=true
|
||||
COPY ./app /code/app
|
||||
|
||||
# run the server
|
||||
CMD [ "pwsh", "-c", "cd /usr/src/app; ./server.ps1" ]
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
|
||||
@@ -0,0 +1,45 @@
|
||||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import RedirectResponse
|
||||
import requests
|
||||
import random
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Response": "Hello World"}
|
||||
|
||||
@app.get("/redirect")
|
||||
def redirect():
|
||||
# get GotHub instances json from codeberg
|
||||
r = requests.get("https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json")
|
||||
|
||||
# get random instance
|
||||
instance = random.choice(r.json())
|
||||
|
||||
# redirect to random instance
|
||||
return RedirectResponse(url=instance["link"])
|
||||
|
||||
@app.get("/redirect/dev")
|
||||
def redirect_dev():
|
||||
# get GotHub instances json from codeberg
|
||||
r = requests.get("https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json")
|
||||
|
||||
# get random instance, branch = dev
|
||||
instance = random.choice([i for i in r.json() if i["branch"] == "dev"])
|
||||
|
||||
# redirect to random instance
|
||||
return RedirectResponse(url=instance["link"])
|
||||
|
||||
@app.get("/redirect/master")
|
||||
def redirect_master():
|
||||
# get GotHub instances json from codeberg
|
||||
r = requests.get("https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json")
|
||||
|
||||
# get random instance, branch = master
|
||||
instance = random.choice([i for i in r.json() if i["branch" == "master"]])
|
||||
|
||||
# redirect to random instance
|
||||
return RedirectResponse(url=instance["link"])
|
||||
@@ -0,0 +1,2 @@
|
||||
fastapi==0.95.0
|
||||
requests==2.28.2
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
Start-PodeServer {
|
||||
# get docker environment variable
|
||||
$docker = $env:DOCKER
|
||||
|
||||
if ($docker) {
|
||||
Add-PodeEndpoint -Address * -Port 8080 -Protocol Http
|
||||
} else {
|
||||
Add-PodeEndpoint -Address localhost -Port 8080 -Protocol Http
|
||||
}
|
||||
|
||||
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
|
||||
Write-PodeJsonResponse -Value @{ Response = 'Hello World' }
|
||||
}
|
||||
|
||||
Add-PodeRoute -Method Get -Path '/random' -ScriptBlock {
|
||||
$instances = Invoke-WebRequest https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json | ConvertFrom-Json
|
||||
|
||||
$instance = $instances | Get-Random
|
||||
|
||||
Move-PodeResponseUrl -Url $instance.link
|
||||
}
|
||||
|
||||
Add-PodeRoute -Method Get -Path '/random/master' -ScriptBlock {
|
||||
$instances = Invoke-WebRequest https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json | ConvertFrom-Json
|
||||
|
||||
$instance = $instances | Where-Object { $_.branch -eq 'master' } | Get-Random
|
||||
|
||||
Move-PodeResponseUrl -Url $instance.link
|
||||
}
|
||||
|
||||
Add-PodeRoute -Method Get -Path '/random/dev' -ScriptBlock {
|
||||
$instances = Invoke-WebRequest https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json | ConvertFrom-Json
|
||||
|
||||
$instance = $instances | Where-Object { $_.branch -eq 'dev' } | Get-Random
|
||||
|
||||
Move-PodeResponseUrl -Url $instance.link
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user