|
@@ -341,14 +341,30 @@ void web_event_handler(struct mg_connection *c, int ev, void *ev_data)
|
|
|
struct mg_connection *web_server_start(struct mg_mgr *mgr, web_ctx_t *ctx)
|
|
struct mg_connection *web_server_start(struct mg_mgr *mgr, web_ctx_t *ctx)
|
|
|
{
|
|
{
|
|
|
struct mg_connection *c;
|
|
struct mg_connection *c;
|
|
|
|
|
+ char listen_url[128];
|
|
|
|
|
|
|
|
- c = mg_http_listen(mgr, WEB_SERVER_LISTEN_URL, web_event_handler, ctx);
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * Read port from DEPLOY_RUN_PORT environment variable (sandbox compat).
|
|
|
|
|
+ * Falls back to WEB_SERVER_PORT (8085) if not set.
|
|
|
|
|
+ */
|
|
|
|
|
+ const char *env_port = getenv("DEPLOY_RUN_PORT");
|
|
|
|
|
+ int port = WEB_SERVER_PORT;
|
|
|
|
|
+ if (env_port != NULL && env_port[0] != '\0') {
|
|
|
|
|
+ int parsed = atoi(env_port);
|
|
|
|
|
+ if (parsed > 0 && parsed < 65536) {
|
|
|
|
|
+ port = parsed;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ snprintf(listen_url, sizeof(listen_url), "http://0.0.0.0:%d", port);
|
|
|
|
|
+
|
|
|
|
|
+ c = mg_http_listen(mgr, listen_url, web_event_handler, ctx);
|
|
|
if (c == NULL) {
|
|
if (c == NULL) {
|
|
|
fprintf(stderr, "[WEB] Failed to start HTTP listener on %s\n",
|
|
fprintf(stderr, "[WEB] Failed to start HTTP listener on %s\n",
|
|
|
- WEB_SERVER_LISTEN_URL);
|
|
|
|
|
|
|
+ listen_url);
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printf("[WEB] HTTP server listening on %s\n", WEB_SERVER_LISTEN_URL);
|
|
|
|
|
|
|
+ printf("[WEB] HTTP server listening on %s\n", listen_url);
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|