mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
38 lines
748 B
C
38 lines
748 B
C
#include "crow.h"
|
|
#include "crow/middlewares/cors.h"
|
|
|
|
|
|
int main()
|
|
{
|
|
// Enable CORS
|
|
crow::App<crow::CORSHandler> app;
|
|
|
|
// Customize CORS
|
|
auto& cors = app.get_middleware<crow::CORSHandler>();
|
|
|
|
// clang-format off
|
|
cors
|
|
.global()
|
|
.headers("X-Custom-Header", "Upgrade-Insecure-Requests")
|
|
.methods("POST"_method, "GET"_method)
|
|
.prefix("/cors")
|
|
.origin("example.com")
|
|
.prefix("/nocors")
|
|
.ignore();
|
|
// clang-format on
|
|
|
|
CROW_ROUTE(app, "/")
|
|
([]() {
|
|
return "Check Access-Control-Allow-Methods header";
|
|
});
|
|
|
|
CROW_ROUTE(app, "/cors")
|
|
([]() {
|
|
return "Check Access-Control-Allow-Origin header";
|
|
});
|
|
|
|
app.port(18080).run();
|
|
|
|
return 0;
|
|
}
|