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
+
+ # Prepare mongo connection
+ var mongo = new MongoClient("mongodb://localhost:27017/")
+ var db = mongo.database("nitweb")
+ var collection = db.collection("stars")
+
# 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("/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_before("/*", new RequestClock)
+ app.use("/api", new APIRouter(model, modelbuilder, mainmodule, catalog, collection))
+ 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
+
+ # Mongo collection used to store ratings.
+ var collection: MongoCollection
+
+ 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))
+ use("/feedback/", new APIFeedbackRouter(model, mainmodule, collection))
+ use("/inheritance/:id", new APIEntityInheritance(model, mainmodule))
+ use("/graph/", new APIGraphRouter(model, mainmodule))
+ use("/docdown/", new APIDocdown(model, mainmodule, modelbuilder))
+ use("/metrics/", new APIMetricsRouter(model, mainmodule))
+ end
+end
+
# build toolcontext
var toolcontext = new ToolContext
var tpl = new Template