X-Git-Url: http://nitlanguage.org diff --git a/src/nitweb.nit b/src/nitweb.nit index 8757a30..a1a41a3 100644 --- a/src/nitweb.nit +++ b/src/nitweb.nit @@ -43,22 +43,68 @@ private class NitwebPhase var model = mainmodule.model var modelbuilder = toolcontext.modelbuilder + # Build catalog + var catalog = new Catalog(modelbuilder) + for mpackage in model.mpackages do + catalog.deps.add_node(mpackage) + for mgroup in mpackage.mgroups do + for mmodule in mgroup.mmodules do + for imported in mmodule.in_importation.direct_greaters do + var ip = imported.mpackage + if ip == null or ip == mpackage then continue + catalog.deps.add_edge(mpackage, ip) + end + end + end + catalog.git_info(mpackage) + catalog.package_page(mpackage) + end + # Run the server var host = toolcontext.opt_host.value or else "localhost" var port = toolcontext.opt_port.value var app = new App - app.use("/random", new RandomAction(model)) + + app.use_before("/*", new RequestClock) + app.use("/api", new APIRouter(model, modelbuilder, mainmodule, catalog)) app.use("/doc/:namespace", new DocAction(model, mainmodule, modelbuilder)) - app.use("/code/:namespace", new CodeAction(model, modelbuilder)) - app.use("/search/:namespace", new SearchAction(model)) - app.use("/uml/:namespace", new UMLDiagramAction(model, mainmodule)) - app.use("/", new TreeAction(model, mainmodule)) + app.use("/*", new StaticHandler(toolcontext.share_dir / "nitweb", "index.html")) + app.use_after("/*", new ConsoleLog) app.listen(host, port.to_i) end end +# Group all api handlers in one router. +class APIRouter + super Router + + # Model to pass to handlers. + var model: Model + + # ModelBuilder to pass to handlers. + var modelbuilder: ModelBuilder + + # Mainmodule to pass to handlers. + var mainmodule: MModule + + # Catalog to pass to handlers. + var catalog: Catalog + + init do + use("/catalog", new APICatalogRouter(model, mainmodule, catalog)) + use("/list", new APIList(model, mainmodule)) + use("/search", new APISearch(model, mainmodule)) + use("/random", new APIRandom(model, mainmodule)) + use("/entity/:id", new APIEntity(model, mainmodule)) + use("/code/:id", new APIEntityCode(model, mainmodule, modelbuilder)) + use("/uml/:id", new APIEntityUML(model, mainmodule)) + use("/linearization/:id", new APIEntityLinearization(model, mainmodule)) + use("/defs/:id", new APIEntityDefs(model, mainmodule)) + end +end + # build toolcontext var toolcontext = new ToolContext var tpl = new Template