Main.vala 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Astralis;
  2. using Invercargill;
  3. using Invercargill.DataStructures;
  4. using Inversion;
  5. using Spry;
  6. /**
  7. * Main.vala - Spry Framework Website
  8. *
  9. * A modern, techy website showcasing the Spry framework and its ecosystem:
  10. * - Astralis: High-performance web server framework
  11. * - Inversion: Dependency injection container
  12. * - Spry: Component-based HTMX web framework
  13. *
  14. * Features:
  15. * - Clean, eye-catching design with purple/blue/green theme
  16. * - Interactive demos with real-time SSE updates
  17. * - Responsive layout with modern CSS
  18. * - Free/Libre open source spirit
  19. */
  20. void main(string[] args) {
  21. int port = args.length > 1 ? int.parse(args[1]) : 8080;
  22. print("═══════════════════════════════════════════════════════════════\n");
  23. print(" 🚀 Spry Framework Website\n");
  24. print("═══════════════════════════════════════════════════════════════\n");
  25. print(" Port: %d\n", port);
  26. print("═══════════════════════════════════════════════════════════════\n");
  27. print(" Pages:\n");
  28. print(" / - Home\n");
  29. print(" /features - Features\n");
  30. print(" /ecosystem - Ecosystem (Astralis, Inversion, Spry)\n");
  31. print(" /demo - Interactive Demo (SSE)\n");
  32. print(" /freedom - Free/Libre Philosophy\n");
  33. print("═══════════════════════════════════════════════════════════════\n");
  34. print(" SSE Endpoints:\n");
  35. print(" /sse/aurora - Aurora updates\n");
  36. print(" /sse/counter - Counter updates\n");
  37. print("═══════════════════════════════════════════════════════════════\n");
  38. print("\nPress Ctrl+C to stop the server\n\n");
  39. try {
  40. var application = new WebApplication(port);
  41. // Enable compression
  42. application.use_compression();
  43. // Add Spry module for component actions
  44. application.add_module<SpryModule>();
  45. // Create shared state instance first, then register it as singleton
  46. var aurora_state = new AuroraState();
  47. application.container.register_singleton<AuroraState>(() => aurora_state);
  48. // Configure templates
  49. var spry_cfg = application.configure_with<SpryConfigurator>();
  50. spry_cfg.add_template<SiteLayoutTemplate>("");
  51. // Register page components
  52. application.add_transient<HomePage>();
  53. application.add_endpoint<HomePage>(new EndpointRoute(HomePage.ROUTE));
  54. application.add_transient<FeaturesPage>();
  55. application.add_endpoint<FeaturesPage>(new EndpointRoute(FeaturesPage.ROUTE));
  56. application.add_transient<EcosystemPage>();
  57. application.add_endpoint<EcosystemPage>(new EndpointRoute(EcosystemPage.ROUTE));
  58. application.add_transient<DemoPage>();
  59. application.add_endpoint<DemoPage>(new EndpointRoute(DemoPage.ROUTE));
  60. application.add_transient<FreedomPage>();
  61. application.add_endpoint<FreedomPage>(new EndpointRoute(FreedomPage.ROUTE));
  62. // Register interactive components (for spry-action)
  63. application.add_transient<AuroraWaveComponent>();
  64. application.add_transient<FeatureCardComponent>();
  65. application.add_transient<CodeBlockComponent>();
  66. application.add_transient<StatCardComponent>();
  67. // Create SSE endpoints (singletons to share state across connections)
  68. var aurora_sse = new AuroraSseEndpoint(aurora_state);
  69. var counter_sse = new CounterSseEndpoint(aurora_state);
  70. // Register SSE endpoints as singletons
  71. application.add_singleton_endpoint<AuroraSseEndpoint>(
  72. new EndpointRoute("/sse/aurora"),
  73. () => aurora_sse
  74. );
  75. application.add_singleton_endpoint<CounterSseEndpoint>(
  76. new EndpointRoute("/sse/counter"),
  77. () => counter_sse
  78. );
  79. // Register action endpoints (HTTP POST to trigger SSE broadcasts)
  80. application.add_endpoint<AuroraActionEndpoint>(
  81. new EndpointRoute("/aurora/action/{action}"),
  82. () => new AuroraActionEndpoint(aurora_sse)
  83. );
  84. application.add_endpoint<CounterActionEndpoint>(
  85. new EndpointRoute("/counter/action/{action}"),
  86. () => new CounterActionEndpoint(counter_sse)
  87. );
  88. // Register CSS as FastResources
  89. application.add_startup_endpoint<FastResource>(new EndpointRoute("/styles/main.css"), () => {
  90. try {
  91. return new FastResource.from_string(Styles.MAIN_CSS)
  92. .with_content_type("text/css; charset=utf-8")
  93. .with_default_compressors();
  94. } catch (Error e) {
  95. error("Failed to create main CSS resource: %s", e.message);
  96. }
  97. });
  98. application.run();
  99. } catch (Error e) {
  100. printerr("Error: %s\n", e.message);
  101. Process.exit(1);
  102. }
  103. }