Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (33 sloc) 1.07 KB
// Copyright 2012, Evan Klitzke <evan@eklitzke.org>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/program_options.hpp>
#include "./src/garfield.h"
namespace po = boost::program_options;
void HelloWorldHandler(garfield::Request *req, garfield::Response *resp) {
resp->headers()->SetHeader("Content-Type", "text/plain");
resp->Write("Hello, world!\n");
}
int main(int argc, char **argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("port,p", po::value<int>()->default_value(8000),
"the port to bind on")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc;
return 1;
}
boost::asio::io_service io;
garfield::SetLogger(garfield::StdErrLogger);
garfield::HTTPServer server(&io);
server.Bind(vm["port"].as<int>());
server.AddRoute("GET", "/", HelloWorldHandler);
server.AddRoute("GET", ".*", garfield::StaticFileHandler);
io.run(); // start the main loop
return 0;
}
Something went wrong with that request. Please try again.