-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmain.cpp
More file actions
28 lines (17 loc) · 815 Bytes
/
main.cpp
File metadata and controls
28 lines (17 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "server_http.hpp"
typedef SimpleWeb::Server<SimpleWeb::HTTP> HttpServer;
using namespace std;
int main() {
// Construct HTTP-server at port 8080 using 1 thread, and without request timeout
HttpServer server(8090, 1, 0);
// Response to all GET requests
server.resource["^.*$"]["GET"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
cout << "Path: " << request -> path << endl;
cout << "Version: " << request -> http_version << endl;
std::string content = "<h1>The web server is working!</h1>";
*response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" << content;
};
cout << "Started server @ " << server.config.port<< endl;
server.start();
cout << "Server stopped" << endl;
}