Skip to content

Commit

Permalink
feat: add home route and api route (#4)
Browse files Browse the repository at this point in the history
* add waitress to run the server

* add the home and api route
  • Loading branch information
jljl1337 authored Dec 20, 2024
1 parent 582fd8a commit 1173c0e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
38 changes: 38 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import requests
import socket

from flask import Flask
from waitress import serve

app = Flask(__name__)

HOSTNAME = socket.gethostname()
API_URL = os.environ.get('API_URL')

@app.route('/')
def home():
html = f'<h1>Hello, World from {HOSTNAME}!</h1>'

if API_URL:
api_content = requests.get(API_URL).content.decode('utf-8')
html = f'{html}{api_content}'

return html

@app.route('/api')
def api():
html = f'<p>Calling {HOSTNAME}</p>'

if API_URL:
api_content = requests.get(API_URL).content.decode('utf-8')
html = f'{html}{api_content}'

return html

if __name__ == '__main__':
host = os.environ.get('HOST', '0.0.0.0')
port = os.environ.get('PORT', 8000)

print(f'Starting server on {host}:{port}')
serve(app, host=host, port=port)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ requires-python = ">=3.13"
dependencies = [
"flask>=3.1.0",
"requests>=2.32.3",
"waitress>=3.0.2",
]
11 changes: 11 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1173c0e

Please sign in to comment.