add static files support and cookie expiration settings

This commit is contained in:
2021-09-11 16:34:43 +03:00
parent 7abdb48ac0
commit 875bfc0823
16 changed files with 35 additions and 16 deletions

View File

@ -95,7 +95,7 @@ def setup_auth(application: web.Application, validator: Auth) -> web.Application
"""
fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
storage = EncryptedCookieStorage(secret_key, cookie_name='API_SESSION')
storage = EncryptedCookieStorage(secret_key, cookie_name="API_SESSION", max_age=validator.max_age)
setup_session(application, storage)
authorization_policy = AuthorizationPolicy(validator)

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp.web import Application
from pathlib import Path
from ahriman.web.views.index import IndexView
from ahriman.web.views.service.add import AddView
@ -31,7 +32,7 @@ from ahriman.web.views.user.login import LoginView
from ahriman.web.views.user.logout import LogoutView
def setup_routes(application: Application) -> None:
def setup_routes(application: Application, static_path: Path) -> None:
"""
setup all defined routes
@ -64,10 +65,13 @@ def setup_routes(application: Application) -> None:
POST /user-api/v1/logout logout from service
:param application: web application instance
:param static_path: path to static files directory
"""
application.router.add_get("/", IndexView, allow_head=True)
application.router.add_get("/index.html", IndexView, allow_head=True)
application.router.add_static("/static", static_path, follow_symlinks=True)
application.router.add_post("/service-api/v1/add", AddView)
application.router.add_post("/service-api/v1/remove", RemoveView)

View File

@ -84,7 +84,7 @@ def setup_service(architecture: str, configuration: Configuration, spawner: Spaw
application.middlewares.append(exception_handler(application.logger))
application.logger.info("setup routes")
setup_routes(application)
setup_routes(application, configuration.getpath("web", "static_path"))
application.logger.info("setup templates")
aiohttp_jinja2.setup(application, loader=jinja2.FileSystemLoader(configuration.getpath("web", "templates")))