From 3a7027bd3e818780cde09754a94b066a6e6f3c7a Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Thu, 13 Jun 2024 12:34:51 +0700
Subject: [PATCH 1/7] add port in database configuration

---
 config/database.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/config/database.py b/config/database.py
index 4291974..49597cd 100644
--- a/config/database.py
+++ b/config/database.py
@@ -3,5 +3,6 @@ db_main = {
     'user'       : 'root',
     'password'   : '',
     'database'   : 'your_db',
+    'port'       : 3306,
     'autocommit' : True,
 }

From 8760144735b4a4e7a3bfcf899ab516c0f61dfd42 Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Thu, 13 Jun 2024 12:43:46 +0700
Subject: [PATCH 2/7] Implement session with beaker

---
 .beaker/data/.noremove | 0
 .gitignore             | 5 +++++
 config/server.py       | 8 +++++++-
 costa.py               | 5 ++++-
 install.sh             | 7 ++++---
 5 files changed, 20 insertions(+), 5 deletions(-)
 create mode 100644 .beaker/data/.noremove

diff --git a/.beaker/data/.noremove b/.beaker/data/.noremove
new file mode 100644
index 0000000..e69de29
diff --git a/.gitignore b/.gitignore
index eeb8a6e..2b8380b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,6 @@
 **/__pycache__
+*.pyc
+venv/
+env/
+.beaker/data/*
+!.beaker/data/.noremove
diff --git a/config/server.py b/config/server.py
index 5830cfc..019e867 100644
--- a/config/server.py
+++ b/config/server.py
@@ -4,8 +4,14 @@ reloader    = False
 debug       = False
 server      = 'gunicorn' # default = 'wsgiref'
 
+session_opts = {
+    'session.type': 'file',
+    'session.cookie_expires': 5*60, # Session expiration in seconds: minutes*seconds
+    'session.data_dir': './beaker/data',
+    'session.auto': True
+}
+
 # cors
-# session
 
 # error page 403
 # error page 404
diff --git a/costa.py b/costa.py
index 997b56a..8bc8677 100644
--- a/costa.py
+++ b/costa.py
@@ -6,7 +6,8 @@
 # You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
 
 import  sys
-from    bottle      import Bottle, run
+from    bottle                  import Bottle, run
+from    beaker.middleware       import SessionMiddleware
 
 import  handler
 
@@ -18,6 +19,8 @@ app = Bottle()
 app.merge(handler.app)
 app.merge(staticdir.app)
 
+app = SessionMiddleware(app, server.session_opts)
+
 run(app,
     host = server.host,
     port = server.port,
diff --git a/install.sh b/install.sh
index 6604a9d..150b2d2 100644
--- a/install.sh
+++ b/install.sh
@@ -1,5 +1,6 @@
 sudo apt-get install -y python3-pip
 pip install --upgrade pip
-pip install bottle
-pip install gunicorn
-pip install mako
+pip install bottle # Micro Framework
+pip install gunicorn # WSGI Server Backend
+pip install beaker # Session & caching library
+pip install mako # Template library

From 5129e205c2d44560b6d7295f2f3f976e4b745da0 Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Thu, 13 Jun 2024 12:47:26 +0700
Subject: [PATCH 3/7] Update README.md

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 2448499..1ebeec4 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@ along with this program.  If not, see https://www.gnu.org/licenses/.
 You need this libraries to use CostaPy:
 - bottle
 - gunicorn
+- beaker
 - mako
 
 You can install it with run this command
@@ -37,6 +38,7 @@ Here is the completed command
     pip install --upgrade pip
     pip install bottle
     pip install gunicorn
+    pip install beaker
     pip install mako
 
 ## Usage

From 5ad8ef5d004f3607a3a6dec3be626bb37ff00866 Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Thu, 13 Jun 2024 13:01:17 +0700
Subject: [PATCH 4/7] Update README.md

---
 README.md | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/README.md b/README.md
index 1ebeec4..0a68588 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,22 @@ along with this program.  If not, see https://www.gnu.org/licenses/.
 
 ## Requirement & Installation
 
+### Clone the repository
+
+Clone the repository with `--recursive` when cloning the repo.
+
+    git clone https://gitea.ditaajipratama.net/aji/costapy.git --recursive
+
+Note that if you forgot the `--recursive` flag you can do:
+
+    git submodule update --init
+
+Note that when submodules have other submodules you need recursive option.
+
+    git submodule update --init --recursive
+
+### Dependencies
+
 You need this libraries to use CostaPy:
 - bottle
 - gunicorn

From da43cec3dd3a540fe34615f4873e1e293b77ed4d Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Sun, 30 Jun 2024 14:32:42 +0700
Subject: [PATCH 5/7] beaker data directory should be hidden

---
 config/server.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config/server.py b/config/server.py
index 019e867..98cb6b0 100644
--- a/config/server.py
+++ b/config/server.py
@@ -7,7 +7,7 @@ server      = 'gunicorn' # default = 'wsgiref'
 session_opts = {
     'session.type': 'file',
     'session.cookie_expires': 5*60, # Session expiration in seconds: minutes*seconds
-    'session.data_dir': './beaker/data',
+    'session.data_dir': './.beaker/data',
     'session.auto': True
 }
 

From 81ff500200fe956410daa4e08c39bb873ec411e0 Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Wed, 31 Jul 2024 10:30:51 +0700
Subject: [PATCH 6/7] Update .gitignore

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 2b8380b..8529b52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ venv/
 env/
 .beaker/data/*
 !.beaker/data/.noremove
+nohup.out

From c2f7f32ddc2d83fe3489a06b4582f0f4c49465f7 Mon Sep 17 00:00:00 2001
From: ditaajipratama <ditaajipratama@protonmail.com>
Date: Wed, 31 Jul 2024 10:33:24 +0700
Subject: [PATCH 7/7] Fixing wrong routes in core staticdir

---
 core/staticdir.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/core/staticdir.py b/core/staticdir.py
index 487dffd..02df303 100644
--- a/core/staticdir.py
+++ b/core/staticdir.py
@@ -1,9 +1,7 @@
-from    bottle      import Bottle, get, static_file
+from    bottle      import Bottle, static_file
 from    config      import directory
 
 app = Bottle()
 
-for items in directory.static:
-    @app.get(items['route'])
-    def static_items(filepath):
-        return static_file(filepath, root=items['root'])
+for item in directory.static:
+    app.route(item['route'], "GET", lambda filepath, root=item['root']: static_file(filepath, root=root) )