admin: Global settings can be specified on the command-line. Removed some previous, less thorough ways of configuring things. #102
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
This commit is contained in:
@ -2319,35 +2319,6 @@ static void _httpd_endpoint_app_socket(tf_http_request_t* request)
|
||||
JS_FreeValue(context, global);
|
||||
}
|
||||
|
||||
static int _tf_httpd_get_tildefriends_int(JSContext* context, const char* arg)
|
||||
{
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue tildefriends = JS_GetPropertyStr(context, global, "tildefriends");
|
||||
JSValue arg_value = JS_GetPropertyStr(context, tildefriends, arg);
|
||||
int value = 0;
|
||||
JS_ToInt32(context, &value, arg_value);
|
||||
JS_FreeValue(context, arg_value);
|
||||
JS_FreeValue(context, tildefriends);
|
||||
JS_FreeValue(context, global);
|
||||
return value;
|
||||
}
|
||||
|
||||
static const char* _tf_httpd_get_tildefriends_arg_string(JSContext* context, const char* arg)
|
||||
{
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue tildefriends = JS_GetPropertyStr(context, global, "tildefriends");
|
||||
JSValue args = JS_GetPropertyStr(context, tildefriends, "args");
|
||||
JSValue arg_value = JS_GetPropertyStr(context, args, arg);
|
||||
const char* value = !JS_IsUndefined(arg_value) ? JS_ToCString(context, arg_value) : NULL;
|
||||
const char* result = value ? tf_strdup(value) : NULL;
|
||||
JS_FreeCString(context, value);
|
||||
JS_FreeValue(context, arg_value);
|
||||
JS_FreeValue(context, args);
|
||||
JS_FreeValue(context, tildefriends);
|
||||
JS_FreeValue(context, global);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _httpd_free_user_data(void* user_data)
|
||||
{
|
||||
tf_free(user_data);
|
||||
@ -2394,10 +2365,6 @@ void tf_httpd_register(JSContext* context)
|
||||
fprintf(stderr, "Failed to register Request.\n");
|
||||
}
|
||||
|
||||
int http_port = _tf_httpd_get_tildefriends_int(context, "http_port");
|
||||
int https_port = _tf_httpd_get_tildefriends_int(context, "https_port");
|
||||
const char* out_http_port_file = _tf_httpd_get_tildefriends_arg_string(context, "out_http_port_file");
|
||||
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue httpd = JS_NewObjectClass(context, _httpd_class_id);
|
||||
|
||||
@ -2408,6 +2375,15 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_http_set_trace(http, tf_task_get_trace(task));
|
||||
JS_SetOpaque(httpd, http);
|
||||
|
||||
int64_t http_port = 0;
|
||||
int64_t https_port = 0;
|
||||
char out_http_port_file[512] = "";
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
tf_ssb_db_get_global_setting_int64(db, "http_port", &http_port);
|
||||
tf_ssb_db_get_global_setting_int64(db, "https_port", &https_port);
|
||||
tf_ssb_db_get_global_setting_string(db, "out_http_port_file", out_http_port_file, sizeof(out_http_port_file));
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
|
||||
if (https_port)
|
||||
{
|
||||
http_user_data_t* user_data = tf_http_get_user_data(http);
|
||||
@ -2463,14 +2439,14 @@ void tf_httpd_register(JSContext* context)
|
||||
JS_SetPropertyStr(context, global, "httpd", httpd);
|
||||
JS_FreeValue(context, global);
|
||||
|
||||
if (http_port > 0 || out_http_port_file)
|
||||
if (http_port > 0 || *out_http_port_file)
|
||||
{
|
||||
httpd_listener_t* listener = tf_malloc(sizeof(httpd_listener_t));
|
||||
*listener = (httpd_listener_t) { 0 };
|
||||
int assigned_port = tf_http_listen(http, http_port, NULL, _httpd_listener_cleanup, listener);
|
||||
tf_printf(CYAN "~😎 Tilde Friends" RESET " " YELLOW VERSION_NUMBER RESET " is now up at " MAGENTA "http://127.0.0.1:%d/" RESET ".\n", assigned_port);
|
||||
|
||||
if (out_http_port_file)
|
||||
if (*out_http_port_file)
|
||||
{
|
||||
const char* actual_http_port_file = tf_task_get_path_with_root(task, out_http_port_file);
|
||||
FILE* file = fopen(actual_http_port_file, "wb");
|
||||
@ -2507,6 +2483,4 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_free((char*)private_key);
|
||||
}
|
||||
}
|
||||
|
||||
tf_free((void*)out_http_port_file);
|
||||
}
|
||||
|
Reference in New Issue
Block a user