Add a runtime switch between httpd implementions. One of which is totally not hooked up yet.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4685 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
58e75ee276
commit
f9940fc436
@ -952,8 +952,9 @@ function stringResponse(response, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadSettings().then(function() {
|
loadSettings().then(function() {
|
||||||
httpd.all("/login", auth.handler);
|
let httpd_impl = (tildefriends.args.httpdc ? httpdc : httpd);
|
||||||
httpd.all("", function(request, response) {
|
httpd_impl.all("/login", auth.handler);
|
||||||
|
httpd_impl.all("", function(request, response) {
|
||||||
let match;
|
let match;
|
||||||
if (request.uri === "/" || request.uri === "") {
|
if (request.uri === "/" || request.uri === "") {
|
||||||
try {
|
try {
|
||||||
@ -1003,7 +1004,8 @@ loadSettings().then(function() {
|
|||||||
return response.end(data);
|
return response.end(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
httpd.registerSocketHandler("/app/socket", app.socket);
|
httpd_impl.registerSocketHandler("/app/socket", app.socket);
|
||||||
|
httpd_impl.start();
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
print('Failed to load settings.');
|
print('Failed to load settings.');
|
||||||
printError({print: print}, error);
|
printError({print: print}, error);
|
||||||
|
@ -521,8 +521,10 @@ function handleConnection(client) {
|
|||||||
let kBacklog = 8;
|
let kBacklog = 8;
|
||||||
let kHost = platform() == 'haiku' ? 'localhost' : '::';
|
let kHost = platform() == 'haiku' ? 'localhost' : '::';
|
||||||
|
|
||||||
let socket = new Socket();
|
function start() {
|
||||||
socket.bind(kHost, tildefriends.http_port).then(function(port) {
|
print('ACTUAL START');
|
||||||
|
let socket = new Socket();
|
||||||
|
socket.bind(kHost, tildefriends.http_port).then(function(port) {
|
||||||
print("bound to", port);
|
print("bound to", port);
|
||||||
print("checking", tildefriends.args.out_http_port_file);
|
print("checking", tildefriends.args.out_http_port_file);
|
||||||
if (tildefriends.args.out_http_port_file) {
|
if (tildefriends.args.out_http_port_file) {
|
||||||
@ -542,11 +544,11 @@ socket.bind(kHost, tildefriends.http_port).then(function(port) {
|
|||||||
logError("[" + new Date() + "] accept error " + error);
|
logError("[" + new Date() + "] accept error " + error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
logError("[" + new Date() + "] bind error " + error);
|
logError("[" + new Date() + "] bind error " + error);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tildefriends.https_port) {
|
if (tildefriends.https_port) {
|
||||||
let tls = {};
|
let tls = {};
|
||||||
let secureSocket = new Socket();
|
let secureSocket = new Socket();
|
||||||
secureSocket.bind(kHost, tildefriends.https_port).then(function() {
|
secureSocket.bind(kHost, tildefriends.https_port).then(function() {
|
||||||
@ -588,6 +590,7 @@ if (tildefriends.https_port) {
|
|||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
logError("[" + new Date() + "] bind error " + error);
|
logError("[" + new Date() + "] bind error " + error);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { all, registerSocketHandler };
|
export { all, start, registerSocketHandler };
|
||||||
|
32
src/httpd.js.c
Normal file
32
src/httpd.js.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "httpd.js.h"
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
static JSValue _httpd_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
|
{
|
||||||
|
tf_printf("HTTPD_ALL UNIMPLEMENTED\n");
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue _httpd_register_socket_handler(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
|
{
|
||||||
|
tf_printf("HTTPD_REGISTER_SOCKET_HANDLER UNIMPLEMENTED\n");
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue _httpd_start(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
|
{
|
||||||
|
tf_printf("HTTPD_START UNIMPLEMENTED\n");
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tf_httpd_register(JSContext* context)
|
||||||
|
{
|
||||||
|
JSValue global = JS_GetGlobalObject(context);
|
||||||
|
JSValue httpd = JS_NewObject(context);
|
||||||
|
JS_SetPropertyStr(context, httpd, "all", JS_NewCFunction(context, _httpd_all, "all", 2));
|
||||||
|
JS_SetPropertyStr(context, httpd, "registerSocketHandler", JS_NewCFunction(context, _httpd_register_socket_handler, "register_socket_handler", 2));
|
||||||
|
JS_SetPropertyStr(context, httpd, "start", JS_NewCFunction(context, _httpd_start, "start", 0));
|
||||||
|
JS_SetPropertyStr(context, global, "httpdc", httpd);
|
||||||
|
JS_FreeValue(context, global);
|
||||||
|
}
|
5
src/httpd.js.h
Normal file
5
src/httpd.js.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "quickjs.h"
|
||||||
|
|
||||||
|
void tf_httpd_register(JSContext* context);
|
@ -3,6 +3,7 @@
|
|||||||
#include "bcrypt.js.h"
|
#include "bcrypt.js.h"
|
||||||
#include "database.js.h"
|
#include "database.js.h"
|
||||||
#include "file.js.h"
|
#include "file.js.h"
|
||||||
|
#include "httpd.js.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "packetstream.h"
|
#include "packetstream.h"
|
||||||
@ -1731,6 +1732,7 @@ void tf_task_activate(tf_task_t* task)
|
|||||||
JS_SetPropertyStr(context, global, "TlsContext", tf_tls_context_register(context));
|
JS_SetPropertyStr(context, global, "TlsContext", tf_tls_context_register(context));
|
||||||
tf_file_register(context);
|
tf_file_register(context);
|
||||||
tf_database_register(context);
|
tf_database_register(context);
|
||||||
|
tf_httpd_register(context);
|
||||||
|
|
||||||
task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db_path);
|
task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db_path);
|
||||||
tf_ssb_set_trace(task->_ssb, task->_trace);
|
tf_ssb_set_trace(task->_ssb, task->_trace);
|
||||||
|
Loading…
Reference in New Issue
Block a user