|
|
@@ -5,52 +5,20 @@ namespace Astralis {
|
|
|
|
|
|
public Container container { get; private set; }
|
|
|
public int port { get; private set; }
|
|
|
-
|
|
|
- /**
|
|
|
- * The application configuration loaded from web-config.json
|
|
|
- */
|
|
|
- public WebConfig config { get; private set; }
|
|
|
|
|
|
- private Server? server;
|
|
|
+ private Server server;
|
|
|
private Pipeline pipeline;
|
|
|
- private bool _port_explicitly_set;
|
|
|
|
|
|
public WebApplication(int? port = null) {
|
|
|
- this._port_explicitly_set = (port != null);
|
|
|
- this.port = port ?? 0;
|
|
|
+ this.port = port ?? int.parse(Environment.get_variable ("ASTRALIS_PORT") ?? "8080");
|
|
|
+ printerr(@"[Astralis] Web application using port $(port)\n");
|
|
|
|
|
|
container = new Container();
|
|
|
pipeline = new Pipeline(container);
|
|
|
- // Server is created in run() after config is loaded
|
|
|
+ server = new Server(this.port, pipeline);
|
|
|
}
|
|
|
|
|
|
public void run() throws Error {
|
|
|
- // Load configuration
|
|
|
- config = WebConfigLoader.load();
|
|
|
-
|
|
|
- // Resolve port if not explicitly set in constructor
|
|
|
- // Priority: constructor arg > config file > env var > default (8080)
|
|
|
- if (!_port_explicitly_set) {
|
|
|
- if (config.has_key("port")) {
|
|
|
- port = config.get_int("port", 8080);
|
|
|
- } else {
|
|
|
- string? env_port = Environment.get_variable("ASTRALIS_PORT");
|
|
|
- if (env_port != null) {
|
|
|
- port = int.parse(env_port);
|
|
|
- } else {
|
|
|
- port = 8080;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- printerr(@"[Astralis] Web application using port $port\n");
|
|
|
-
|
|
|
- // Create server with resolved port
|
|
|
- server = new Server(port, pipeline);
|
|
|
-
|
|
|
- // Register config as singleton in DI container
|
|
|
- add_singleton<WebConfig>(() => config);
|
|
|
-
|
|
|
// Ensure router is registered last so that it is the last component in the pipeline.
|
|
|
add_component<EndpointRouter>();
|
|
|
|