Browse Source

adding support for gunicorn, to allow url's with prefixes

pull/30/head
mb 1 year ago
parent
commit
db7bb5bfce
  1. 12
      Makefile
  2. 43
      README.md
  3. 6
      octomode.py
  4. 1
      requirements.txt
  5. 10
      templates/base.html
  6. 2
      templates/start.html

12
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

43
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: <http://localhost:5001> or <http://mydomainname.ext:5001>.
Open the application at port `5001`, for example: <http://localhost:5001> or <https://mydomainname.ext:5001>.
### 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 <https://mydomainname.ext/octomode/>, 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

6
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('/<name>/')
def main(name):
return redirect(f"/{ name }/pad")
return redirect(url_for("pad", name=name))
@APP.route('/<name>/pad/')
def pad(name):

1
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

10
templates/base.html

@ -21,20 +21,20 @@ window.addEventListener('load', function () {
nav.id = 'nav';
nav.innerHTML = `
<h1>{{ name }} <a href="/"><em class="octomode">in octomode</em></a></h1>
<h1>{{ name }} <a href="{{ url_for('index') }}"><em class="octomode">in octomode</em></a></h1>
<div id="buttons">
<a href="/{{ name }}/pad"><button>pad</button></a>
<a href="{{ url_for('pad', name=name) }}"><button>pad</button></a>
<span id="click_md" class="info" tabindex="1">🌐</span>
<div id="show_md" class="hidden"><input type="text" name="pad" value="{{ pad_url }}/{{ name }}.md"></div>
<a href="/{{ name }}/stylesheet"><button>stylesheet</button></a>
<a href="{{ url_for('stylesheet', name=name) }}"><button>stylesheet</button></a>
<span id="click_css" class="info" tabindex="1">🌐</span>
<div id="show_css" class="hidden"><input type="text" name="pad" value="{{ pad_url }}/{{ name }}.css"></div>
<a href="/{{ name }}/html"><button>html</button></a>
<a href="{{ url_for('html', name=name) }}"><button>html</button></a>
<a href="/{{ name }}/pdf"><button>pdf</button></a>
<a href="{{ url_for('pdf', name=name) }}"><button>pdf</button></a>
</div>`;
document.body.insertBefore(nav, document.body.firstChild);

2
templates/start.html

@ -6,7 +6,7 @@
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
</head>
<body class="start-page">
<form action="/" method="POST">
<form action="{{ url_for('index') }}" method="POST">
<h1><input type="submit" value="open"> <input type="text" name="name"> <em class="octomode">in octomode</em></h1>
</form>
</body>

Loading…
Cancel
Save