Add Options enpoints and Access-Control-Allow-Headers to satisfy CORS rules

This commit is contained in:
Felix Hellmann 2023-06-01 10:47:53 +02:00
parent f7882e2d69
commit 5bbc030338
No known key found for this signature in database
GPG key ID: BD9441B47AFCEC40

View file

@ -719,7 +719,10 @@ int main(int argc, char **argv)
Server svr;
svr.set_default_headers({ {"Access-Control-Allow-Origin", "*"} });
svr.set_default_headers({
{"Access-Control-Allow-Origin", "*"},
{"Access-Control-Allow-Headers", "content-type"}
});
svr.Get("/", [](const Request &, Response &res)
{ res.set_content("<h1>llama.cpp server works</h1>", "text/html"); });
@ -874,6 +877,11 @@ int main(int argc, char **argv)
}
});
svr.Options(R"(/.*)", [&llama](const Request &req, Response &res)
{
return res.set_content("", "application/json");
});
svr.Post("/tokenize", [&llama](const Request &req, Response &res)
{
json body = json::parse(req.body);