-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add home route and api route (#4)
* add waitress to run the server * add the home and api route
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ requires-python = ">=3.13" | |
dependencies = [ | ||
"flask>=3.1.0", | ||
"requests>=2.32.3", | ||
"waitress>=3.0.2", | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.