Skip to content

Commit

Permalink
trying again
Browse files Browse the repository at this point in the history
  • Loading branch information
tblanarik committed Sep 9, 2024
1 parent 34f7357 commit d006083
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions spotbot.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
'''
import azure.functions as func
import requests
import os
app = func.FunctionApp()
@app.function_name(name="SpotBotTrigger")
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS, methods=["POST"])
def main(req: func.HttpRequest) -> func.HttpResponse:
content = req.get_json()
target_url = os.getenv('TARGET_URL')
if not target_url:
return func.HttpResponse("Error: TARGET_URL environment variable is not set.", status_code=500)
response = requests.post(target_url, json=content)
return func.HttpResponse(response.text, status_code=response.status_code)
'''

import azure.functions as func
import logging

app = func.FunctionApp()
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.function_name(name="HttpTrigger1")
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS)
def test_function(req: func.HttpRequest) -> func.HttpResponse:
@app.route(route="http_trigger1")
def http_trigger1(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
return func.HttpResponse(
"This HTTP triggered function executed successfully.",
status_code=200

name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')

if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)

0 comments on commit d006083

Please sign in to comment.