When I used netlify the blog would auto update and publish the blog. I wanted to recreate this in my setup. I began researching what I could do. I made a flask server that gets a key and runs a bunch of commands when it gets a post request.
from flask import Flask, request import os import threading app = Flask(__name__) def update_static(): source = "/home/nullrequest/myblog" os.chdir(source) os.system("git pull") os.system("hugo --gc --minify -b https://nullrequest.com/") os.system("echo 'finshed running thread'") @app.route("/", methods=["GET", "POST"]) def update(): if request.method == "GET": return "Your not supposed to be here" elif request.method == "POST": key = request.form["key"] if key == os.environ.get("key"): update_thread = threading.Thread(target=update_static) update_thread.start() return "Hello Octocat"
As you can see its pretty sleek. Using a web hook you can get GitHub to send you a update post request with any value to your server. Its pretty effective at replicating what happened in netlify setup except there they used git hubs API. Honestly if I wasn’t so confused by docs I would have used the API.
With that I end the dev part of this series. I may add more stuff as time goes on. One thing for sure I am going to be writing is about why you should/shouldn’t try this. For some people its really simpler to use a hosting provider due to the benefits they have.
— This is nullrequest signing offcomments powered by Disqus