diff --git a/redstring/server.py b/redstring/server.py index 63d3a57..50279ff 100644 --- a/redstring/server.py +++ b/redstring/server.py @@ -1,3 +1,40 @@ +""" +Logic for serving a collection of documents through a web frontend. +""" +import argparse +import os + +from flask import Flask, redirect, url_for, current_app, render_template + +from redstring.parser import load + + +CONFIG_ENVVAR = 'REDSTRING_CONFIG' + +app = Flask(__name__) + + +@app.route('/') +def root(): + return redirect(url_for('index')) + + +@app.route('/index/') +def index(): + with open('scratch/test.json') as f: + document = load(f) + return render_template('doc.jinja', document=document) + + def main(): - print("Hello, world!") - print(__name__) + parser = argparse.ArgumentParser(description="Run the redstring server.") + parser.add_argument("--config", help="Config file path.") + args = parser.parse_args() + + config_path = args.config or os.environ.get(CONFIG_ENVVAR) or '/etc/redstring.conf' + # TODO + document_folder = args.config # TODO + + app.config['root'] = document_folder + + app.run(debug=True, port=5000)