From 67e60c0da4512f0a6f3d1c76448c783bf2c92aa4 Mon Sep 17 00:00:00 2001 From: StrangeBytesDev Date: Fri, 10 May 2024 09:39:14 -0700 Subject: [PATCH] Basic fix to cors check --- examples/server/server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index a76c0cded..22d21453d 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -124,6 +124,7 @@ struct server_params { std::string chat_template = ""; std::string system_prompt = ""; + std::vector http_cors_origin = {"http://localhost:8080", "http://127.0.0.1:8080"}; std::vector api_keys; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT @@ -2972,7 +2973,7 @@ int main(int argc, char ** argv) { svr->set_default_headers({{"Server", "llama.cpp"}}); // Disallow CORS requests from any origin not specified in the --http-cors-origin flag - svr.set_pre_routing_handler([&sparams](const httplib::Request &req, httplib::Response &res) { + svr->set_pre_routing_handler([&sparams](const httplib::Request &req, httplib::Response &res) { res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin")); res.set_header("Access-Control-Allow-Credentials", "true"); res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");