Crow/examples/example_catchall.cpp
The-EDev 576690bf14 Made catchall work with 404 or 405 errors
snuck in a fix for release.py where version name wouldn't change
also snuck in slight improvement in finding blueprint (removed extra if statement)
2021-08-21 04:49:17 +03:00

28 lines
568 B
C++

#define CROW_MAIN
#include <crow.h>
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")([](){return "Hello";});
//Setting a custom route for any URL that isn't defined, instead of a simple 404.
CROW_CATCHALL_ROUTE(app)
([](crow::response& res) {
if (res.code == 404)
{
res.body = "The URL does not seem to be correct.";
}
else if (res.code == 405)
{
res.body = "The HTTP method does not seem to be correct.";
}
res.end();
});
app.port(18080).run();
}