forked from cory/tildefriends
core: Remove app.js.
This commit is contained in:
@@ -741,7 +741,6 @@ static void _httpd_auth_query_after_work(tf_ssb_t* ssb, int status, void* user_d
|
||||
|
||||
uv_timer_start(&work->timer, _httpd_app_on_timer, 6 * 1000, 6 * 1000);
|
||||
|
||||
/* What now? */
|
||||
tf_free((void*)cookie);
|
||||
JS_FreeCString(context, name_string);
|
||||
|
||||
@@ -752,7 +751,7 @@ static void _httpd_auth_query_after_work(tf_ssb_t* ssb, int status, void* user_d
|
||||
request->user_data = work;
|
||||
}
|
||||
|
||||
static void _tf_httpd_endpoint_app_socket_c(tf_http_request_t* request)
|
||||
void tf_httpd_endpoint_app_socket(tf_http_request_t* request)
|
||||
{
|
||||
const char* header_connection = tf_http_request_get_header(request, "connection");
|
||||
const char* header_upgrade = tf_http_request_get_header(request, "upgrade");
|
||||
@@ -786,65 +785,3 @@ static void _tf_httpd_endpoint_app_socket_c(tf_http_request_t* request)
|
||||
tf_ssb_run_work(ssb, _httpd_auth_query_work, _httpd_auth_query_after_work, work);
|
||||
}
|
||||
}
|
||||
|
||||
static void _tf_httpd_endpoint_app_socket_js(tf_http_request_t* request)
|
||||
{
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue exports = JS_GetPropertyStr(context, global, "exports");
|
||||
JSValue app_socket = JS_GetPropertyStr(context, exports, "app_socket");
|
||||
|
||||
JSValue request_object = JS_NewObject(context);
|
||||
JSValue headers = JS_NewObject(context);
|
||||
for (int i = 0; i < request->headers_count; i++)
|
||||
{
|
||||
JS_SetPropertyStr(context, headers, request->headers[i].name, JS_NewString(context, request->headers[i].value));
|
||||
}
|
||||
JS_SetPropertyStr(context, request_object, "headers", headers);
|
||||
|
||||
JSValue response = tf_httpd_make_response_object(context, request);
|
||||
tf_http_request_ref(request);
|
||||
|
||||
JSValue args[] = {
|
||||
request_object,
|
||||
response,
|
||||
};
|
||||
|
||||
JSValue result = JS_Call(context, app_socket, JS_NULL, tf_countof(args), args);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
|
||||
for (int i = 0; i < tf_countof(args); i++)
|
||||
{
|
||||
JS_FreeValue(context, args[i]);
|
||||
}
|
||||
|
||||
JS_FreeValue(context, app_socket);
|
||||
JS_FreeValue(context, exports);
|
||||
JS_FreeValue(context, global);
|
||||
}
|
||||
|
||||
void tf_httpd_endpoint_app_socket(tf_http_request_t* request)
|
||||
{
|
||||
static bool checked_env;
|
||||
static bool use_c;
|
||||
if (!checked_env)
|
||||
{
|
||||
char buffer[8] = { 0 };
|
||||
size_t buffer_size = sizeof(buffer);
|
||||
use_c = uv_os_getenv("TF_APP_C", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
|
||||
checked_env = true;
|
||||
}
|
||||
|
||||
if (use_c)
|
||||
{
|
||||
_tf_httpd_endpoint_app_socket_c(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tf_httpd_endpoint_app_socket_js(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user