Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,111 @@
.exe
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use an official Python runtime as a parent image
FROM python:3.10-slim

WORKDIR /app

COPY main.py requirements.txt ./
COPY static/ static/
COPY templates/ templates/

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5000

# Define environment variable
ENV FLASK_APP=main.py
ENV FLASK_RUN_HOST=0.0.0.0

# Run app.py when the container launches
CMD ["flask", "run"]
26 changes: 26 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flask import Flask, request, render_template

app = Flask(__name__)
counter = 0


@app.route("/", methods=["GET"])
def main():
return render_template("home.html"), 200


@app.route("/post", methods=["POST", "GET"])
def postcounter():
global counter
if request.method == "POST":
counter += 1
return render_template("home.html", message="success")


@app.route("/get", methods=["GET"])
def getcounter():
return render_template("home.html", counter=counter)


if __name__ == "__main__":
app.run(debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask>=2.3.3
55 changes: 55 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
text-align: center;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 50%;
max-width: 600px;
}

.main-title {
color: #333;
font-size: 24px;
margin-bottom: 10px;
}

h2 {
color: #555;
margin-bottom: 20px;
}

.form-button {
margin: 10px 0;
}

.btn {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
text-decoration: none;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
width: 100px;
}

.post-btn {
background-color: #28a745;
}

.btn:hover {
opacity: 0.9;
}
26 changes: 26 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Counter Service Application</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
</head>

<body>
<div class="container">
<h1 class="main-title">Counter Service Application</h1>
{% if counter == null and message != null : %}
<h3>Successfully increment the counter</h3>
{%elif counter == null and message == null %}
<h3></h3>
{% else %}
<h3>POST Requests Count: {{ counter }}</h3>
{% endif %}
<form action="/post" method="post" class="form-button">
<button type="submit" class="btn post-btn">Post</button>
</form>
<form action="/get" method="get" class="form-button">
<button type="submit" class="btn post-btn">Get</button>
</form>
</div>
</body>
</html>