Crow/flask.h

59 lines
1018 B
C
Raw Normal View History

#pragma once
#include <string>
#include <functional>
#include <memory>
#include <future>
#include <stdint.h>
#include <type_traits>
#include "http_server.h"
#include "routing.h"
// TEST
#include <iostream>
2014-03-30 13:53:56 +00:00
namespace flask
{
class Flask
{
public:
Flask()
{
}
2014-04-01 13:58:52 +00:00
response handle(const request& req)
{
return router_.handle(req);
}
auto route(std::string&& rule)
-> typename std::result_of<decltype(&Router::new_rule)(Router, std::string&&)>::type
{
return router_.new_rule(std::move(rule));
}
Flask& port(std::uint16_t port)
{
port_ = port;
return *this;
}
void validate()
{
router_.validate();
}
2014-03-30 13:53:56 +00:00
void run()
{
validate();
Server<Flask> server(this, port_);
server.run();
2014-03-30 13:53:56 +00:00
}
private:
uint16_t port_ = 80;
2014-04-01 12:25:16 +00:00
Router router_;
2014-03-30 13:53:56 +00:00
};
};