M .gitignore => .gitignore +1 -1
@@ 5,5 5,5 @@
/.env
/assets/css/
/assets/script/
+/data/guestbook.json
/logs/access.log
-/guestbook.json
A data/.gitkeep => data/.gitkeep +0 -0
M docker-compose.production.yml => docker-compose.production.yml +1 -0
@@ 17,6 17,7 @@ services:
build: .
image: kvikshaug.no
volumes:
+ - "./data:/app/data"
- "./logs:/app/logs"
environment:
- ENVIRONMENT=production
M src/kvikshaug/app.py => src/kvikshaug/app.py +5 -5
@@ 17,14 17,14 @@ if app.config["DEBUG"]:
app.jinja_env.undefined = StrictUndefined
# Initialize guestbook if not yet created.
-if not os.path.exists("guestbook.json"):
- with open("guestbook.json", "w") as file_:
+if not os.path.exists("data/guestbook.json"):
+ with open("data/guestbook.json", "w") as file_:
json.dump([], file_)
@app.route("/")
def home():
- with open("guestbook.json") as file_:
+ with open("data/guestbook.json") as file_:
guestbook = json.load(file_)
for message in guestbook:
message["datetime"] = datetime.strptime(message["datetime"], "%Y-%m-%d %H:%M")
@@ 37,9 37,9 @@ def guestbook():
message = request.form.get("message", "").strip()
if message == "":
return redirect("/#guestbook")
- with open("guestbook.json") as file_:
+ with open("data/guestbook.json") as file_:
guestbook = json.load(file_)
- with open("guestbook.json", "w") as file_:
+ with open("data/guestbook.json", "w") as file_:
guestbook.append({
"message": message,
"ip": request.remote_addr,