| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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<StatumModule>();
- var web_config = application.container.create_transient_scope().resolve<WebConfig>();
- // 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<UsmWebConfig>(() => config);
- application.add_singleton<RepositoryService>();
- var statum = application.configure_with<StatumConfigurator>();
- // spry:pages-begin
- statum.add_page<HomePage, HomeEntrypoint>();
- statum.add_page<RepoBrowsePage, RepoBrowseEntrypoint>();
- statum.add_page<PackageDetailPage, PackageDetailEntrypoint>();
- // spry:pages-end
- // spry:actions-begin
- statum.action<SearchPackagesAction>();
- // spry:actions-end
- // spry:resources-begin
- statum.add_resource<MainCssResource>();
- // 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<PackagesListingEndpoint>(new EndpointRoute("/repo/{name}/PACKAGES.usml"));
- application.add_endpoint<RepositoryDefinitionEndpoint>(new EndpointRoute("/repo/{name}/repo.usmr"));
- application.add_endpoint<PackageDownloadEndpoint>(new EndpointRoute("/repo/{name}/{file}"));
- if (config.installer == InstallerSource.PATH) {
- application.add_endpoint<InstallerScriptEndpoint>(new EndpointRoute("/{file}"));
- }
- application.run();
- return 0;
- } catch (Error e) {
- printerr("[usm-web] Error: %s\n", e.message);
- return 1;
- }
- }
|