Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
putuwaw committed Dec 5, 2022
0 parents commit fa10ba4
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 7

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 7
36 changes: 36 additions & 0 deletions .github/workflows/flask.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Flask Application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
**/__pycache__
.pytest_cache
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Putu Widyantara Artanta Wibawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# flask-app-vercel

![Flask](https://img.shields.io/badge/Flask-000000?style=for-the-badge&logo=flask&logoColor=white)
![Vercel](https://img.shields.io/badge/vercel-%23000000.svg?style=for-the-badge&logo=vercel&logoColor=white)

Flask application templates hosted on Vercel, included with unit testing and Python modules.

## Structure 📂
```
flask-app-vercel
├── .github
├── handlers
├── modules
├── static
│ ├── images
│ ├── scripts
│ └── styles
├── templates
├── tests
├── .gitignore
├── LICENSE
├── README.md
├── app.py
├── requirements.txt
└── vercel.json
```
- [.github](.github/) is a folder that used to place Github related stuff, like CI pipeline.
- [handlers](handlers/) contain handler to handling HTTP request methods.
- [modules](modules/) contain the main modules of the app.
- [static](static/) contain static files like images, CSS, and JavaScript files.
- [templates](templates/) contain the file that will be rendered for display in the browser.
- [tests](tests/) contain unit test of the app.
- [.gitignore](.gitignore) is a file to exclude some folders like venv.
- [LICENSE](LICENSE) is a file that contains the license used in this app.
- [README.md](README.md) is the file you are reading now.
- [app.py](app.py) is the main file of this app.
- [requirements.txt](requirements.txt) is a file that contains a list of dependencies used in this app.
- [vercel.json](vercel.json) is a file that contains configuration and override the default behavior of Vercel.

## Installation 🛠️
- Clone the repository:
```
git clone https://github.com/putuwaw/flask-app-vercel.git
```
- Create a virtual environment:
```
python -m venv venv
```
- Activate virtual environment:
```
source venv/Scripts/activate
```
- Install dependencies:
```
pip install -r requirements.txt
```
- Run app:
```
python app.py
```
- Run test:
```
pytest
```
9 changes: 9 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Flask
from handlers.routes import configure_routes

app = Flask(__name__)

configure_routes(app)

if __name__ == "__main__":
app.run(debug=True)
Empty file added handlers/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions handlers/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import render_template
from modules import modules

def configure_routes(app):
@app.route("/")
def index():
hello = modules.hello()
content = modules.content()
return render_template("index.html", hello=hello, content=content)
Empty file added modules/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions modules/modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def hello():
return "Hello, World!"

def content():
return '''
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
'''
Binary file added requirements.txt
Binary file not shown.
Binary file added static/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/scripts/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// scripts.js
1 change: 1 addition & 0 deletions static/styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* style.css */
15 changes: 15 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %} {% endblock %}</title>
<link rel="icon" type="image/png" href="{{ url_for('static', filename='images/favicon.png') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='styles/styles.css') }}">
</head>
<body>
{% block body %} {% endblock %}
<script src="{{ url_for('static', filename='scripts/scripts.js') }}"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block title %} Flask App - Vercel {% endblock %}
{% block body %}
<h1>{{hello}}</h1>
<p>{{content}}</p>
{% endblock %}
Empty file added tests/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask
from handlers.routes import configure_routes


def test_index():
app = Flask(__name__, template_folder="../templates")
configure_routes(app)
app.testing = True
client = app.test_client()
response = client.get('/')
assert response.status_code == 200
18 changes: 18 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"builds": [
{
"src": "app.py",
"use": "@vercel/python"
},
{
"src": "static/**",
"use": "@vercel/static"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "app.py"
}
]
}

1 comment on commit fa10ba4

@vercel
Copy link

@vercel vercel bot commented on fa10ba4 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

flask-app-vercel – ./

flask-app-vercel-putuwaw.vercel.app
flask-app-vercel.vercel.app
flask-app-vercel-git-main-putuwaw.vercel.app

Please sign in to comment.