using Astralis; using Inversion; using Statum; using UsmWeb; int main(string[] args) { int port = 8080; string? repo_dir = null; for (int i = 1; i < args.length; i++) { var arg = args[i]; if (arg == "--repo" && i + 1 < args.length) { repo_dir = args[++i]; } else if (arg.has_prefix("--repo=")) { repo_dir = arg.substring("--repo=".length); } else if (arg.has_prefix("--port=")) { port = int.parse(arg.substring("--port=".length)); } else { port = int.parse(arg); } } repo_dir = repo_dir ?? Environment.get_variable("USM_WEB_REPO_DIR"); try { var application = new WebApplication(port); application.use_compression(); application.add_module(); var web_config = application.container.create_transient_scope().resolve(); // Precedence: --repo argument > USM_WEB_REPO_DIR > the "usm-web" // section's "repo" key (UsmWebConfig.load) > /repo var config = UsmWebConfig.load(web_config, repo_dir); application.add_singleton(() => config); application.add_singleton(); var statum = application.configure_with(); // spry:pages-begin statum.add_page(); statum.add_page(); statum.add_page(); // spry:pages-end // spry:actions-begin statum.action(); // spry:actions-end // spry:resources-begin statum.add_resource(); // spry:resources-end // USM-serving endpoints. The exact /repo/{name}/PACKAGES.usml and // /repo/{name}/repo.usmr routes must precede /repo/{name}/{file} // (which also matches them), and the /{file} catch-all — serving // only /install-usm.sh — must come last. application.add_endpoint(new EndpointRoute("/repo/{name}/PACKAGES.usml")); application.add_endpoint(new EndpointRoute("/repo/{name}/repo.usmr")); application.add_endpoint(new EndpointRoute("/repo/{name}/{file}")); if (config.installer == InstallerSource.PATH) { application.add_endpoint(new EndpointRoute("/{file}")); } application.run(); return 0; } catch (Error e) { printerr("[usm-web] Error: %s\n", e.message); return 1; } }