c/quickwebserver.c
/**
 * JS-function to start server
 * 
 */
JS-function to start server
JS - function to start server
static JSValue startServer(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
	if (argc != 2) {
        return JS_ThrowReferenceError(ctx, "[QuickWebServer] Wrong number of arguments for server launching");
	}
	if (!JS_IsFunction(ctx, argv[0])) {
        return JS_ThrowReferenceError(ctx, "[QuickWebServer] Main server event callback function not found");
	}
    if (!JS_IsNumber(argv[1])) {
        return JS_ThrowTypeError(ctx, "[QuickWebServer] Port is not a number");
    }
    ARRAY_CREATE(serverRequests, 2, 0);
	QWS.serverContext = ctx;
	QWS.callbackFunction = argv[0];
	QWS.requestsCount = 1;
	int port;
	JS_ToInt32(ctx, &port, argv[1]);
  	struct http_server_s* server = http_server_init(port, requestCallback);
	http_server_listen(server);
	return JS_NewInt32(ctx, 0);
}
static JSValue startServer ( JSContext * ctx , JSValueConst this_val , int argc , JSValueConst * argv ) { if ( argc != 2 ) { return JS_ThrowReferenceError ( ctx , " " ) ; } if ( ! JS_IsFunction ( ctx , argv [ 0 ] ) ) { return JS_ThrowReferenceError ( ctx , " " ) ; } if ( ! JS_IsNumber ( argv [ 1 ] ) ) { return JS_ThrowTypeError ( ctx , " " ) ; } ARRAY_CREATE ( serverRequests , 2 , 0 ) ; QWS . serverContext = ctx ; QWS . callbackFunction = argv [ 0 ] ; QWS . requestsCount = 1 ; int port ; JS_ToInt32 ( ctx , & port , argv [ 1 ] ) ; struct http_server_s * server = http_server_init ( port , requestCallback ) ; http_server_listen ( server ) ; return JS_NewInt32 ( ctx , 0 ) ; }
JS-function to start server
JS - function to start server