feat: add REST API for categories, game creation, and guessing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
c1f7ed44c1
commit
7c3a8f22cf
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
|
||||
import click
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
||||
from db import get_engine, get_session_factory, init_db
|
||||
from handlers.main import MainHandler
|
||||
from handlers.game import GameHandler
|
||||
from handlers.api import (
|
||||
CategoriesHandler,
|
||||
NewGameHandler,
|
||||
GameStateHandler,
|
||||
GuessHandler,
|
||||
)
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def make_app(session_factory=None):
|
||||
return tornado.web.Application(
|
||||
[
|
||||
(r"/", MainHandler),
|
||||
(r"/game", GameHandler),
|
||||
(r"/api/categories", CategoriesHandler),
|
||||
(r"/api/game/new", NewGameHandler),
|
||||
(r"/api/game/([^/]+)", GameStateHandler),
|
||||
(r"/api/game/([^/]+)/guess", GuessHandler),
|
||||
],
|
||||
template_path=os.path.join(BASE_DIR, "templates"),
|
||||
static_path=os.path.join(BASE_DIR, "static"),
|
||||
session_factory=session_factory,
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("--port", default=8888, type=int, help="Port to listen on.")
|
||||
def main(port):
|
||||
engine = get_engine()
|
||||
init_db(engine)
|
||||
session_factory = get_session_factory(engine)
|
||||
app = make_app(session_factory=session_factory)
|
||||
app.listen(port)
|
||||
print(f"Server started at http://localhost:{port}")
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user