Skip to content

Commit 196e19e

Browse files
authored
Merge pull request #2 from tblanarik/make-urls-config
Make the target and destination URLs configurable
2 parents 6f47290 + f7bc668 commit 196e19e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ Spotbot is a simple webserver that listens for HTTP POST requests and forwards t
2727

2828
To run the webserver, execute the following command:
2929
```sh
30-
python spotbot.py
30+
TARGET_URL=<target_url> DESTINATION_URL=<destination_url> python spotbot.py
3131
```
3232

33-
The webserver will start and listen on port 5000.
33+
Replace `<target_url>` with the actual target URL and `<destination_url>` with the desired port number for the Flask app. If `DESTINATION_URL` is not set, the default port will be 5000.
3434

3535
## Sending a POST Request to the `/forward` Endpoint
3636

@@ -53,7 +53,7 @@ To run the webserver using Docker, follow these steps:
5353

5454
2. Run the Docker container:
5555
```sh
56-
docker run -p 5000:5000 spotbot
56+
docker run -p 5000:5000 -e TARGET_URL=<target_url> -e DESTINATION_URL=<destination_url> spotbot
5757
```
5858

59-
The webserver will start and listen on port 5000 inside the Docker container.
59+
Replace `<target_url>` with the actual target URL and `<destination_url>` with the desired port number for the Flask app. If `DESTINATION_URL` is not set, the default port will be 5000.

spotbot.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from flask import Flask, request
22
import requests
3+
import os
34

45
app = Flask(__name__)
56

67
@app.route('/forward', methods=['POST'])
78
def forward():
89
content = request.get_json()
9-
target_url = 'http://example.com/target' # Replace with the actual target URL
10+
target_url = os.getenv('TARGET_URL') # Replace with the actual target URL
11+
if not target_url:
12+
return "Error: TARGET_URL environment variable is not set.", 500
1013
response = requests.post(target_url, json=content)
1114
return response.text, response.status_code
1215

1316
if __name__ == '__main__':
14-
app.run(port=5000)
17+
app.run(port=os.getenv('DESTINATION_URL', 5000))

0 commit comments

Comments
 (0)