Commit a08fedc6 authored by James Allenby's avatar James Allenby
Browse files

Updated main.cc to provide better example

parent 7d1537b0
#include <fstream>
#include "jampserver.hh"
std::string get_file_contents(const char *filename)
{
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}
throw(errno);
}
int main()
{
std::string file = get_file_contents("rules.ninja");
// Create a JAMP server object
JAMP::Server server;
// Register all URIs that you may want to use
server.All("/", [](auto& request, auto& response) {
response.SetResponseCode(JAMP::Code::HTTP_200);
response.Write("hello");
response.Write("Hey there! Welcome to JAMP.");
response.Close();
});
server.All("/rules", [file](auto& request, auto& response) {
// Register particular URIs on different paths
server.All("/rules", [](auto& request, auto& response) {
response.SetResponseCode(JAMP::Code::HTTP_200);
response.Write(file);
response.Write("These are the rules... don't break them.");
response.Close();
});
// Start the server finally
server.Start(10000);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment