a Nomadnet page server based on flask.
| .gitignore | add a gitignore and use the default Reticulum config directory. | |
| __init__.py | change the default announce interval. | |
| fileServer.py | initial commit. | |
| LICENCE | add a very valid licence, add support for announcing every 6hours and show the 'started' message only after the paths were registered. | |
| README.md | fix alignment issues(again) in the readme's examples. | |
| session.py | initial commit. | |
nomadServe
NomadServe is a nomadnet page server that does not use CGI or fastCGI but instead aims to work more like flask. This means that this is not made for people who aren't developers but gives more power to people who are.
Examples
To run the examples, the example's python file should be in the same folder than the one containing the nomadServe folder.
Simple Routes
This example serves the index page and an about page.
from nomadServe import NomadServe
app = NomadServe("(nomadServe example) Simple Routes")
@app.route("/page/index.mu")
@app.route("/")
def index():
return f"""#!c=0
>`cThis is the index page!`a
This is an example nomadServe server.
`[About nomadServe`:/about`]
"""
@app.route("/about")
def about():
return "nomadServe is the coolest Nomadnet server!!"
app.start()
Session Store: Login
This example stores data in the session storage and implements a simple login page and an index page, telling the user if he is logged in or not.
from nomadServe import NomadServe
from nomadServe.session import SessionStorage
app = NomadServe("(nomadServe example) Session Store: Login")
session_storage = SessionStorage()
@app.route("/page/index.mu")
@app.route("/")
def index(link_id):
session = session_storage.get(link_id)
if session is None:
return f"""#!c=0
>`c You are not logged in.
[Login Page`:/login`]
"""
else:
username = session["username"]
return f"""#!c=0
>`c Welcome, {username}!
`aThis can only be seen when you're logged in!
`[Login Page`:/login`]
"""
@app.route("/login")
def login(data, link_id):
if data is not None:
username = data.get("field_username", None)
if username is not None:
session_storage.add(link_id, {"username": username})
return f"#!c=0\nWelcome, {username}!\n`[Home`:/`]"
else:
return "#!c=0\nError"
else:
return "#!c=0\n`B444`<username`>`b `[Login`:/login`username]\n`[Home`:/`]"
app.start()
File Server
This example will serve all files in the 'files' directory on the server's /file/ path.
from nomadServe import NomadServe, fileServer
app = NomadServe("(nomadServe example) File Server")
fileServer.register(app, "files", "file")
@app.route("/page/index.mu")
@app.route("/")
def index(link_id):
session = session_storage.get(link_id)
if session is not None:
username = session["username"]
message = f"Welcome, {username}!"
else:
message = "You are not logged in"
return f"""#!c=0
>`c{message}`aThis is an example nomadServe server.
`[Files`:/files`]
`[Login Page`:/login`]
"""
@app.route("/login")
def login(data, link_id):
if data is not None:
username = data.get("field_username", None)
if username is not None:
session_storage.add(link_id, {"username": username})
return f"#!c=0\nWelcome, {username}!\n`[Home`:/`]"
else:
return "#!c=0\nError"
else:
return "#!c=0\n`B444`<username`>`b `[Login`:/login`username]\n`[Home`:/`]"
app.start()