代码拉取完成,页面将自动刷新
#include "compile_run.hpp"
#include "../comm/httplib.h"
using namespace ns_compiler;
using namespace ns_runner;
using namespace ns_compile_and_run;
using namespace httplib;
void Usage(const string proc)
{
std::cerr << "Usage: " << "\n\t" << proc << "port" << endl;
}
int main(int argc, char *argv[])
{
if(argc != 2)
{
Usage(argv[0]);
return 1;
}
Server svr;
//用户如果请求根目录下的hello服务,服务器就会调用回调函数并返回响应
svr.Get("/hello", [](const Request &req, Response &resp){
//content-type中text/plain表示文本格式
//编码格式设置为为utf-8
resp.set_content("hello httplib!", "text/plain;charset=utf-8");
});
svr.Post("/compile_and_run", [](const Request &req, Response &resp){
//用户请求的服务正文是我们想要的json string
string in_json = req.body;
string out_json;
if(!in_json.empty())
{
CompileAndRun::Start(in_json, &out_json);
resp.set_content(out_json, "application/json;charset=utf-8");
}
});
svr.listen("0.0.0.0", atoi(argv[1]));
// std::string file = "code";
// Compiler::Compile(file);
// Runner::Run(file, 10, 10);
// //充当客户端请求的json串
// string in_json;
// Json::Value in_value;
// //c++11原生字符串:R"()"
// in_value["code"] = R"(#include<iostream>
// int main()
// {
// std::cout << "hello world" << std::endl;
// return 0;
// })";
// in_value["input"] = "";
// in_value["cpu_limit"] = 1;
// in_value["mem_limit"] = 10240 * 3;
// Json::FastWriter writer;
// in_json = writer.write(in_value);
// // cout << in_json << endl;
// string out_json;
// CompileAndRun::Start(in_json, &out_json);
// cout << out_json << endl;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。