Skip to content

Commit

Permalink
(#27)
Browse files Browse the repository at this point in the history
* Implement basic api flask app for the base
  • Loading branch information
kggold4 committed May 24, 2023
1 parent 05d9ba5 commit 86b3029
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
18 changes: 18 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use an official Python runtime as the base image
FROM python:3.9

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file and install the dependencies
COPY ../requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code into the container
COPY . .

# Expose the port on which your Flask app runs (default is 5000)
EXPOSE 5000

# Define the command to run your application
CMD ["python", "app.py"]
22 changes: 22 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Server API

### Docker Build

```shell
docker build -t server-api-<version> .
```

### Docker Run

```shell
docker run -d -p 80:5000 server-api-<version>
```

### Set url

Access your API: With the container running, your Flask API should be accessible via the host machine's IP address or domain name using port 80. If the IP address of your Ubuntu machine is 192.168.0.100, you can access your API at http://192.168.0.100.
Make sure to configure any necessary firewall rules or port forwarding settings to allow inbound connections to port 80 on your Ubuntu machine.

Note: If you want to make your API accessible from the internet, you'll need to configure port forwarding on your router to forward incoming traffic on port 80 to the internal IP address of your Ubuntu machine.

That's it! Your Flask API is now deployed on Docker, and other applications can connect to it using the specified URL.
6 changes: 6 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

from api.server_api import app

if __name__ == '__main__':
app.run(debug=bool(os.getenv("DEBUG_MODE", default=False)))
8 changes: 8 additions & 0 deletions api/server_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import uuid

from flask import Flask, render_template

app = Flask(__name__)
app.config['SECRET_KEY'] = str(uuid.uuid4())

from api.server_api import routes
19 changes: 19 additions & 0 deletions api/server_api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import request

from api.server_api import app


@app.route('/')
def index():
data = {"url": "all news"}
return data


@app.route('/get_similar_articles', methods=['POST'])
def get_similar_articles():
if 'url' in request.args:
# todo: check in cluster db
article_url: str = request.args['url']
return {"similar": ["similar 1", "similar 2"], "article_url": article_url}
else:
return "Need to get current url"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ setuptools==65.5.1
requests~=2.28.2
bs4~=0.0.1
beautifulsoup4~=4.12.0
lxml~=4.9.2
lxml~=4.9.2
Flask~=2.3.2

0 comments on commit 86b3029

Please sign in to comment.