Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Pass program arguments for listen address and port into http server.
Kishore Nallan0b9d5e386af4
diff --git a/include/http_server.h b/include/http_server.hindex 03d39f81..a1297e10 100644--- a/include/http_server.h+++ b/include/http_server.h@@ -76,6 +76,10 @@ private:static h2o_accept_ctx_t accept_ctx;static std::vector<route_path> routes;+ std::string listen_address;++ uint32_t listen_port;+h2o_hostconf_t *hostconf;static void on_accept(h2o_socket_t *listener, const char *err);@@ -92,7 +96,7 @@ private:static int catch_all_handler(h2o_handler_t *self, h2o_req_t *req);public:- HttpServer();+ HttpServer(std::string listen_address, uint32_t listen_port);~HttpServer();diff --git a/src/http_server.cpp b/src/http_server.cppindex bcdeeff6..cd02e2d5 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -8,7 +8,8 @@ h2o_context_t HttpServer::ctx;h2o_accept_ctx_t HttpServer::accept_ctx;std::vector<route_path> HttpServer::routes;-HttpServer::HttpServer() {+HttpServer::HttpServer(std::string listen_address, uint32_t listen_port):+ listen_address(listen_address), listen_port(listen_port) {h2o_config_init(&config);hostconf = h2o_config_register_host(&config, h2o_iovec_init(H2O_STRLIT("default")), 65535);register_handler(hostconf, "/", catch_all_handler);@@ -35,8 +36,8 @@ int HttpServer::create_listener(void) {memset(&addr, 0, sizeof(addr));addr.sin_family = AF_INET;- addr.sin_addr.s_addr = htonl(INADDR_ANY); //htonl(INADDR_LOOPBACK);- addr.sin_port = htons(8088);+ addr.sin_port = htons(listen_port);+ inet_pton(AF_INET, listen_address.c_str(), &(addr.sin_addr));if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ||setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_flag, sizeof(reuseaddr_flag)) != 0 ||@@ -61,7 +62,8 @@ int HttpServer::run() {accept_ctx.hosts = config.hosts;if (create_listener() != 0) {- fprintf(stderr, "failed to listen to 127.0.0.1:1088:%s\n", strerror(errno));+ std::cerr << "Failed to listen on " << listen_address << ":" << listen_port << std::endl+ << "Error: " << strerror(errno) << std::endl;return 1;}diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cppindex e5f74926..c6dba806 100644--- a/src/main/typesense_server.cpp+++ b/src/main/typesense_server.cpp@@ -13,7 +13,7 @@ int main(int argc, char **argv) {CollectionManager & collectionManager = CollectionManager::get_instance();collectionManager.init(&store);- HttpServer server;+ HttpServer server(options.get<std::string>("listen-address"), options.get<uint32_t>("listen-port"));server.post("/collection", post_create_collection);server.post("/collection/:collection", post_add_document);