Added XMLHttpRequest Level2 support.

This commit is contained in:
yhirose 2015-07-17 21:52:46 -04:00
parent 43aae85df3
commit 5079d3406a

View File

@ -7,18 +7,6 @@
using namespace httplib; using namespace httplib;
using namespace std; using namespace std;
void open_url(const char* url)
{
string cmd;
#ifdef _MSC_VER
cmd += "start ";
#else
cmd += "open ";
#endif
cmd += url;
system(cmd.c_str());
}
function<void (size_t, size_t, const string&)> makeJSONFormatter(string& json) function<void (size_t, size_t, const string&)> makeJSONFormatter(string& json)
{ {
auto init = make_shared<bool>(true); auto init = make_shared<bool>(true);
@ -86,11 +74,10 @@ int main(void)
} }
json += "}"; json += "}";
res.set_content(json, "application/json"); res.set_header("Access-Control-Allow-Origin", "*");
}); res.set_header("Access-Control-Allow-Methods", "POST");
svr.get("/stop", [&](const Request& req, Response& res) { res.set_content(json, "application/json");
svr.stop();
}); });
svr.set_error_handler([](const Request& req, Response& res) { svr.set_error_handler([](const Request& req, Response& res) {
@ -100,8 +87,6 @@ int main(void)
res.set_content(buf, "text/html"); res.set_content(buf, "text/html");
}); });
open_url("http://localhost:1234");
svr.listen("localhost", 1234); svr.listen("localhost", 1234);
return 0; return 0;