diff --git a/Makefile b/Makefile index f23781a..be476bb 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ #! make -default: run +include .env +export + +default: local setup: @if [ ! -d ".venv" ]; then python3 -m venv .venv && .venv/bin/pip install -r requirements.txt; fi -run: - @.venv/bin/python octomode.py +local: + @.venv/bin/python octomode.py + +action: + @SCRIPT_NAME=${OCTOMODE_APPLICATION_ROOT} .venv/bin/gunicorn -b localhost:${OCTOMODE_PORTNUMBER} --reload octomode:APP diff --git a/README.md b/README.md index 96425de..0fdca92 100644 --- a/README.md +++ b/README.md @@ -81,21 +81,37 @@ You can clone this repository to run octomode on your own computer or server. `git clone https://git.vvvvvvaria.org/varia/octomode.git` -`cd octomode` +Install the dependencies. + +All the `python` dependencies are listed in `requirements.txt` + +To install them, you can run: + +`make setup` + +This creates a virtual environment at `.venv/` and installs all the dependencies here. + +Next to this, you also need to install `pandoc`. -`make setup` (sets up a virtual environment and install the requirements, you only need to do this once) +`sudo apt install pandoc` + +Now we need to configure *octomode*: + +`cd octomode` `nano .env` Configure your environment, save the following configuration settings as to a file called `.env`: ``` +OCTOMODE_APPLICATION_ROOT=XXX OCTOMODE_PORTNUMBER=XXX OCTOMODE_PAD_URL=XXX OCTOMODE_PAD_API_URL=XXX OCTOMODE_PAD_API_KEY=XXX ``` +- **OCTOMODE_APPLICATION_ROOT**: *optional*, default: `/` - **OCTOMODE_PORTNUMBER**: *optional*, default: `5001` - **OCTOMODE_PAD_URL**: *optional*, default: `https://pad.vvvvvvaria.org/` - **OCTOMODE_PAD_API_URL**: *optional*, default: `https://pad.vvvvvvaria.org/api/1.2.15/` @@ -105,25 +121,24 @@ OCTOMODE_PAD_API_KEY=XXX `make run` (runs the Flask application) -Open the application at port `5001`, for example: or . +Open the application at port `5001`, for example: or . -### Dependencies +## Install octomode with an URL prefix -`python` dependencies are listed in `requirements.txt` +If you want to install octomode with an URL prefix, like , then you can use the gunicorn WSGI. -To install them, you can run: +If you have ran the `make setup` command already, then `gunicorn` is already installed. -`make setup` +Configure your application root URL in your `.env` file. -This creates a virtual environment at `.venv/` and installs all the dependencies here. +You can simply run *octomode* now with the following command to run it with `gunicorn` (and not the built-in Flask dev server): -### Other configurations on the server +`make action` + +### Dependencies -* Configure the webserver to listen to the port of the flask application, for example with a subdomain -* Expand the current https certificate for a subdomain -* Restart nginx (`sudo service reload nginx`) -* To keep the flask application running in the background: add a new config to supervisor (`cp /etc/supervisor/conf.d/previousexample.conf /etc/supervisor/conf.d/new.conf`) -* Restart supervisor (`sudo service reload supervisor`) +* pandoc +* python dependencies, see: `requirements.txt` ## Use octomode locally diff --git a/octomode.py b/octomode.py index a0358e2..70409cd 100755 --- a/octomode.py +++ b/octomode.py @@ -1,6 +1,6 @@ import os import json -from flask import Flask, request, render_template, redirect +from flask import Flask, request, render_template, redirect, url_for from urllib.request import urlopen from urllib.parse import urlencode @@ -108,13 +108,13 @@ def index(): exts = ['.md', '.css'] for ext in exts: create_pad_on_first_run(name, ext) - return redirect(f"/{ name }/pad/") + return redirect(url_for("pad", name=name)) else: return render_template('start.html', pad_url=APP.config['PAD_URL']) @APP.route('//') def main(name): - return redirect(f"/{ name }/pad") + return redirect(url_for("pad", name=name)) @APP.route('//pad/') def pad(name): diff --git a/requirements.txt b/requirements.txt index 82264c5..b92dc15 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ MarkupSafe==2.0.1 Werkzeug==2.0.2 bleach==4.1.0 click==8.0.3 +gunicorn==20.1.0 importlib-metadata==4.10.1 itsdangerous==2.0.1 pkg-resources==0.0.0 diff --git a/templates/base.html b/templates/base.html index ef81a70..db3da7b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -21,20 +21,20 @@ window.addEventListener('load', function () { nav.id = 'nav'; nav.innerHTML = ` -

{{ name }} in octomode

+

{{ name }} in octomode

- + 🌐 - + 🌐 - + - +
`; document.body.insertBefore(nav, document.body.firstChild); diff --git a/templates/start.html b/templates/start.html index 8f2b08c..890a6c1 100644 --- a/templates/start.html +++ b/templates/start.html @@ -6,7 +6,7 @@ -
+

in octomode