From 97d6e65bb8d1314216833ddd43c7a0bacb902b7b Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 15 Dec 2020 15:09:33 +0100 Subject: [PATCH] serve pages, too --- techrec/server.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/techrec/server.py b/techrec/server.py index 4471e05..c23700a 100644 --- a/techrec/server.py +++ b/techrec/server.py @@ -5,8 +5,8 @@ import os import unicodedata from datetime import datetime -from fastapi import FastAPI, HTTPException, Response -from fastapi.responses import RedirectResponse +from fastapi import FastAPI, HTTPException, Request, Response +from fastapi.responses import FileResponse, RedirectResponse from fastapi.staticfiles import StaticFiles from .cli import common_pre @@ -299,9 +299,13 @@ def home(): return RedirectResponse("/new.html") -for page in ("new.html", "old.html", "archive.html"): - # route f"/{page}" → get_config()["STATIC_PAGES"] + page - pass +@app.route("/new.html") +@app.route("/old.html") +@app.route("/archive.html") +def serve_pages(request: Request): + page = request.url.path[1:] + fpath = os.path.join(get_config()["STATIC_PAGES"], page) + return FileResponse(fpath) if __name__ == "__main__":