Inspired by other well-known C++ web frameworks, FabCc's positioning is a network framework, which is characterized by low code, high performance, strong type, super standard, safest and awesome. The logo uses Nod's logo, and the design comes from Command and Conquer(CNC).
On April 12th, the ultra high definition 8k remastered version arrived. Support Gzip compression of web pages to reduce traffic consumption. Fixed various bugs, compatible with modern JSON and C++11, fixed keep alive mechanism, and launched best C++20 stack less coroutine. The following is a comparison chart.
std::string_view sv = k(&O::id);
will return "O
.id
"(can be modified by constexpr in C++14 and higher versions).cmake --build ./build --config Release -j
to compile in parallel.using namespace fc;
int main() {
App app; Timer t;
app.file_type({ "html","htm","ico","css","js","json","svg","png","jpg","gif","txt","wasm","mp4","webm","mp3","wav","aac" })
.sub_api("/", app.serve_file("static")).set_keep_alive(4, 3, 2).set_use_max_mem(600.0)
.set_file_download(true);//Set to enable file downloads, this is the new interface.
app.default_route() = [](Req& req, Res& res)_ctx {
res.set_content_type("text/html;charset=UTF-8", 23); res.set_status(404);
res.write_async_s([] {
char name[64]; gethostname(name, 64); Json x{ {"header", name} }; return mustache::load("404NotFound.html").render(x);
}); co_return;//Set default route
};
app["/get_upload"] = [](Req& req, Res& res)_ctx {
res.write_async([] {
auto f = fc::directory_iterator(fc::directory_ + fc::upload_path_); Json x;
std::set<std::string_view> extentions = { "mp4", "mp3", "webm", "wav", "mkv" };
for (auto v : f) {
if (std::find(extentions.begin(), extentions.end(), fc::toLowerCase(v.ext)) != extentions.end()) {
x.push_back({ {"name",v.name.substr(fc::directory_.size())}, {"size",v.size} });
}
} return x;
}); co_return;//Get the list of uploaded files
};
app["/read_file"] = [](Req& req, Res& res)_ctx { res.write_async([] { Json x = json::read_file("test.json"); return x; }); co_return; };
app["/json"] = [](Req& req, Res& res)_ctx {
Json x; Book b{ "ts", Person{"js",6, Book{"plus" }, vec<Book>{ {"1", Person {"sb" }}, {"2", Person {"sb" }} }} };
b.person->book = Book{ "rs", null, vec<Person>{ {"?"}, {"!"} } }; x = b; res.write(x); co_return;//Return json
};
app["/serialization"] = [](Req& req, Res& res)_ctx {
Json x = json::parse(R"(
{"name":"ts","person":{"name":"js","age":33,"book":{"name":"ojbk","person":{"name":"fucker","age":0},
"persons":[{"name":"stupid","age":1},{"name":"idoit","age":2},{"name":"bonkers","age":3,"book":{"name":"sb"}}]}}}
)"); Book b = x.get<Book>(); b.person->book->persons[2].name = "wwzzgg"; x = b; res.write(x.dump()); co_return;//Deserialization and serialization
};
app["/api"] = [](Req& req, Res& res)_ctx { res.write(res.app._print_routes()); co_return; };//Return to routing list
app.post("/api") = [](Req& req, Res& res)_ctx {
BP bp(req, 1000); co_await bp.run(); std::string s;//Support for uploading files with a total size of 1000MB
for (auto p : bp.params) {
s << (p.key + ": ") << p.value << ", ";
}
s.pop_back(); s.pop_back(); res.write(s); co_return;
};
app["/del"] = [](Req&, Res& res)_ctx { res.app["/"] = nullptr; res.write("The routing of the home page is delete!!"); co_return; };
app["/timer"] = [](Req& req, Res& res)_ctx {
req.setTimeout([] { raise(SIGINT); }, 6000); res.write("Turn off the server timer and start the countdown!"); co_return;
};
//Start the server, also supports ipv6
app.http_serve(8080);
}
Out-of-source build with CMake is recommended.
delete clean cmake cache if build fails.
cmake -B build
followed by additional compilation options.
Use vcpkg -DCMAKE_TOOLCHAIN_FILE=../vcpkg.cmake
Use llhttp parser -DLLHTTP=1
Use openssl -DOPENSSL=1
cmake -B build -DLLHTTP=0 -DOPENSSL=0
cmake --build ./build --config Release -j
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。