X-Git-Url: http://nitlanguage.org diff --git a/src/nitweb.nit b/src/nitweb.nit index 61117a5..370e2a2 100644 --- a/src/nitweb.nit +++ b/src/nitweb.nit @@ -15,27 +15,9 @@ # Runs a webserver based on nitcorn that render things from model. module nitweb -import popcorn::pop_config -import popcorn::pop_auth import frontend import web - -redef class NitwebConfig - - # Github client id used for Github OAuth login. - # - # * key: `github.client_id` - # * default: `` - var github_client_id: String is lazy do return value_or_default("github.client.id", "") - - # Github client secret used for Github OAuth login. - # - # * key: `github.client_secret` - # * default: `` - var github_client_secret: String is lazy do - return value_or_default("github.client.secret", "") - end -end +import doc::doc_down redef class ToolContext @@ -63,29 +45,31 @@ private class NitwebPhase # Build the nitweb config from `toolcontext` options. fun build_config(toolcontext: ToolContext, mainmodule: MModule): NitwebConfig do - var config_file = toolcontext.opt_config.value - if config_file == null then config_file = "nitweb.ini" var config = new NitwebConfig( - config_file, toolcontext.modelbuilder.model, mainmodule, toolcontext.modelbuilder) + var config_file = toolcontext.opt_config.value + if config_file == null then config.default_config_file = "nitweb.ini" + config.parse_options(args) var opt_host = toolcontext.opt_host.value - if opt_host != null then config["app.host"] = opt_host + if opt_host != null then config.ini["app.host"] = opt_host var opt_port = toolcontext.opt_port.value - if opt_port >= 0 then config["app.port"] = opt_port.to_s + if opt_port >= 0 then config.ini["app.port"] = opt_port.to_s return config end redef fun process_mainmodule(mainmodule, mmodules) do var config = build_config(toolcontext, mainmodule) + config.model.nitdoc_md_processor = config.md_processor + config.build_catalog var app = new App app.use_before("/*", new SessionInit) app.use_before("/*", new RequestClock) - app.use("/api", new NitwebAPIRouter(config)) + app.use("/api", new APIRouter(config)) app.use("/login", new GithubLogin(config.github_client_id)) app.use("/oauth", new GithubOAuthCallBack(config.github_client_id, config.github_client_secret)) app.use("/logout", new GithubLogout) @@ -96,29 +80,6 @@ private class NitwebPhase end end -# Group all api handlers in one router. -class NitwebAPIRouter - super APIRouter - - init do - use("/catalog", new APICatalogRouter(config)) - use("/list", new APIList(config)) - use("/search", new APISearch(config)) - use("/random", new APIRandom(config)) - use("/entity/:id", new APIEntity(config)) - use("/code/:id", new APIEntityCode(config)) - use("/uml/:id", new APIEntityUML(config)) - use("/linearization/:id", new APIEntityLinearization(config)) - use("/defs/:id", new APIEntityDefs(config)) - use("/feedback/", new APIFeedbackRouter(config)) - use("/inheritance/:id", new APIEntityInheritance(config)) - use("/graph/", new APIGraphRouter(config)) - use("/docdown/", new APIDocdown(config)) - use("/metrics/", new APIMetricsRouter(config)) - use("/user", new GithubUser) - end -end - # build toolcontext var toolcontext = new ToolContext var tpl = new Template