| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using Astralis;
- using Invercargill;
- using Invercargill.DataStructures;
- using Inversion;
- using Spry;
- /**
- * Main.vala - Spry Framework Website
- *
- * A modern, techy website showcasing the Spry framework and its ecosystem:
- * - Astralis: High-performance web server framework
- * - Inversion: Dependency injection container
- * - Spry: Component-based HTMX web framework
- *
- * Features:
- * - Clean, eye-catching design with purple/blue/green theme
- * - Interactive demos with real-time SSE updates
- * - Responsive layout with modern CSS
- * - Free/Libre open source spirit
- */
- void main(string[] args) {
- int port = args.length > 1 ? int.parse(args[1]) : 8080;
-
- print("═══════════════════════════════════════════════════════════════\n");
- print(" 🚀 Spry Framework Website\n");
- print("═══════════════════════════════════════════════════════════════\n");
- print(" Port: %d\n", port);
- print("═══════════════════════════════════════════════════════════════\n");
- print(" Pages:\n");
- print(" / - Home\n");
- print(" /features - Features\n");
- print(" /ecosystem - Ecosystem (Astralis, Inversion, Spry)\n");
- print(" /demo - Interactive Demo (SSE)\n");
- print(" /freedom - Free/Libre Philosophy\n");
- print("═══════════════════════════════════════════════════════════════\n");
- print(" SSE Endpoints:\n");
- print(" /sse/aurora - Aurora updates\n");
- print(" /sse/counter - Counter updates\n");
- print("═══════════════════════════════════════════════════════════════\n");
- print("\nPress Ctrl+C to stop the server\n\n");
-
- try {
- var application = new WebApplication(port);
-
- // Enable compression
- application.use_compression();
-
- // Add Spry module for component actions
- application.add_module<SpryModule>();
-
- // Create shared state instance first, then register it as singleton
- var aurora_state = new AuroraState();
- application.container.register_singleton<AuroraState>(() => aurora_state);
-
- // Configure templates
- var spry_cfg = application.configure_with<SpryConfigurator>();
- spry_cfg.add_template<SiteLayoutTemplate>("");
-
- // Register page components
- application.add_transient<HomePage>();
- application.add_endpoint<HomePage>(new EndpointRoute(HomePage.ROUTE));
-
- application.add_transient<FeaturesPage>();
- application.add_endpoint<FeaturesPage>(new EndpointRoute(FeaturesPage.ROUTE));
-
- application.add_transient<EcosystemPage>();
- application.add_endpoint<EcosystemPage>(new EndpointRoute(EcosystemPage.ROUTE));
-
- application.add_transient<DemoPage>();
- application.add_endpoint<DemoPage>(new EndpointRoute(DemoPage.ROUTE));
-
- application.add_transient<FreedomPage>();
- application.add_endpoint<FreedomPage>(new EndpointRoute(FreedomPage.ROUTE));
-
- // Register interactive components (for spry-action)
- application.add_transient<AuroraWaveComponent>();
- application.add_transient<FeatureCardComponent>();
- application.add_transient<CodeBlockComponent>();
- application.add_transient<StatCardComponent>();
-
- // Create SSE endpoints (singletons to share state across connections)
- var aurora_sse = new AuroraSseEndpoint(aurora_state);
- var counter_sse = new CounterSseEndpoint(aurora_state);
-
- // Register SSE endpoints as singletons
- application.add_singleton_endpoint<AuroraSseEndpoint>(
- new EndpointRoute("/sse/aurora"),
- () => aurora_sse
- );
- application.add_singleton_endpoint<CounterSseEndpoint>(
- new EndpointRoute("/sse/counter"),
- () => counter_sse
- );
-
- // Register action endpoints (HTTP POST to trigger SSE broadcasts)
- application.add_endpoint<AuroraActionEndpoint>(
- new EndpointRoute("/aurora/action/{action}"),
- () => new AuroraActionEndpoint(aurora_sse)
- );
- application.add_endpoint<CounterActionEndpoint>(
- new EndpointRoute("/counter/action/{action}"),
- () => new CounterActionEndpoint(counter_sse)
- );
-
- // Register CSS as FastResources
- application.add_startup_endpoint<FastResource>(new EndpointRoute("/styles/main.css"), () => {
- try {
- return new FastResource.from_string(Styles.MAIN_CSS)
- .with_content_type("text/css; charset=utf-8")
- .with_default_compressors();
- } catch (Error e) {
- error("Failed to create main CSS resource: %s", e.message);
- }
- });
-
- application.run();
-
- } catch (Error e) {
- printerr("Error: %s\n", e.message);
- Process.exit(1);
- }
- }
|