| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,13 @@ project(expresscpp LANGUAGES CXX) | |||
| 4 | 4 | ||
| 5 | 5 | execute_process(COMMAND git | |
| 6 | 6 | describe | |
| 7 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| 8 | + RESULT_VARIABLE retcode | ||
| 7 | 9 | OUTPUT_VARIABLE PROJECT_VERSION) | |
| 10 | + if(NOT "${retcode}" STREQUAL "0") | ||
| 11 | + set(PROJECT_VERSION "0.0.0") | ||
| 12 | + message(STATUS "could not get git tag, setting version to ${PROJECT_VERSION}") | ||
| 13 | + endif() | ||
| 8 | 14 | ||
| 9 | 15 | ### | |
| 10 | 16 | ### options | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,5 +4,5 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ```bash | |
| 6 | 6 | # returns a json object containing the registered routes and handlers | |
| 7 | - curl localhost:8080/debug | ||
| 7 | + curl localhost:8081/debug | ||
| 8 | 8 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ int main() { | |||
| 37 | 37 | expresscpp->Use(expresscpp->GetStaticFileProvider(doc_root)); | |
| 38 | 38 | ||
| 39 | 39 | // start listening for requests and block until ctrl+C | |
| 40 | - const uint16_t port = 8080u; | ||
| 40 | + const uint16_t port = 8081u; | ||
| 41 | 41 | expresscpp | |
| 42 | 42 | ->Listen(port, []() { std::cout << "Example app listening on port " << port << std::endl; }) | |
| 43 | 43 | .Block(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,17 @@ | |||
| 1 | 1 | #include "gtest/gtest.h" | |
| 2 | + #include "nlohmann/json.hpp" | ||
| 2 | 3 | ||
| 3 | 4 | #include "expresscpp/expresscpp.hpp" | |
| 4 | 5 | #include "expresscpp/types.hpp" | |
| 5 | 6 | #include "test_utils.hpp" | |
| 6 | 7 | ||
| 8 | + using namespace std::literals; | ||
| 9 | + | ||
| 7 | 10 | // Performs an HTTP GET and prints the response | |
| 8 | 11 | TEST(HelloWorld, GetRequest) { | |
| 9 | 12 | auto expresscpp = std::make_shared<ExpressCpp>(); | |
| 10 | 13 | ||
| 11 | - expresscpp->Listen(8080, []() { | ||
| 14 | + expresscpp->Listen(8081, []() { | ||
| 12 | 15 | const auto s = getResponse("/", boost::beast::http::verb::get); | |
| 13 | 16 | EXPECT_GE(s.size(), 0); | |
| 14 | 17 | }); | |
@@ -22,20 +25,24 @@ TEST(HelloWorld, UseRouter) { | |||
| 22 | 25 | res->Json(R"({"status":"ok"})"); | |
| 23 | 26 | }); | |
| 24 | 27 | ||
| 25 | - expresscpp->Get("/api/v0/users", [](auto req, auto res) { | ||
| 26 | - std::cout << req->path_ << std::endl; | ||
| 27 | - res->Json(R"({"users": | ||
| 28 | + const auto json_response = R"({"users": | ||
| 28 | 29 | [ | |
| 29 | 30 | {"id": "39811e5d-cb4b-4dcf-a857-df3813fa89f3"}, | |
| 30 | 31 | {"id": "4edfc753-b817-42d5-9266-d045f8945e2e"} | |
| 31 | 32 | ] | |
| 32 | - })"); | ||
| 33 | - }); | ||
| 33 | + })"sv; | ||
| 34 | 34 | ||
| 35 | - // TODO: add here a request and expectation | ||
| 35 | + expresscpp->Get("/api/v0/users", [=](auto req, auto res) { | ||
| 36 | + std::cout << req->path_ << std::endl; | ||
| 37 | + res->Json(json_response); | ||
| 38 | + }); | ||
| 36 | 39 | ||
| 37 | - expresscpp->Listen(8080, []() { | ||
| 40 | + expresscpp->Listen(8081, [=]() { | ||
| 38 | 41 | const auto s = getResponse("/", boost::beast::http::verb::get); | |
| 39 | - EXPECT_GE(s.size(), 0); | ||
| 42 | + EXPECT_EQ(s, R"({"status":"ok"})"); | ||
| 43 | + const auto ss = getResponse("/api/v0/users", boost::beast::http::verb::get); | ||
| 44 | + const auto expected = nlohmann::json::parse(json_response); | ||
| 45 | + const auto received = nlohmann::json::parse(json_response); | ||
| 46 | + EXPECT_EQ(expected.dump(), received.dump()); | ||
| 40 | 47 | }); | |
| 41 | 48 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ TEST(HttpMethods, TestDiffentMethods) { | |||
| 12 | 12 | expresscpp->Delete("/", [](auto /*req*/, auto res) { res->Send("delete"); }); | |
| 13 | 13 | expresscpp->Patch("/", [](auto /*req*/, auto res) { res->Send("patch"); }); | |
| 14 | 14 | ||
| 15 | - expresscpp->Listen(8080, []() { | ||
| 15 | + expresscpp->Listen(8081, []() { | ||
| 16 | 16 | const auto s_get = getResponse("/", boost::beast::http::verb::get); | |
| 17 | 17 | const auto s_post = getResponse("/", boost::beast::http::verb::post); | |
| 18 | 18 | const auto s_delete = getResponse("/", boost::beast::http::verb::delete_); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ TEST(RoutingTable, TestBasicRouting) { | |||
| 11 | 11 | expresscpp->Get("/c", [](auto /*req*/, auto res) { res->Send("get_c"); }); | |
| 12 | 12 | expresscpp->Post("/d", [](auto /*req*/, auto res) { res->Send("post_d"); }); | |
| 13 | 13 | ||
| 14 | - expresscpp->Listen(8080, [=]() { | ||
| 14 | + expresscpp->Listen(8081, [=]() { | ||
| 15 | 15 | const auto a = getResponse("/a", boost::beast::http::verb::get); | |
| 16 | 16 | EXPECT_EQ(a, "get_a"); | |
| 17 | 17 | ||
@@ -38,13 +38,15 @@ TEST(RoutingTable, TestDefaultRouting) { | |||
| 38 | 38 | res->Send(error); | |
| 39 | 39 | }); | |
| 40 | 40 | ||
| 41 | - expresscpp->Listen(8080, [=]() { | ||
| 41 | + expresscpp->Listen(8081, [=]() { | ||
| 42 | 42 | const auto a = getResponse("/a", boost::beast::http::verb::get); | |
| 43 | 43 | EXPECT_EQ(a, "get_a"); | |
| 44 | 44 | ||
| 45 | 45 | auto e = getResponse("/e", boost::beast::http::verb::post); | |
| 46 | 46 | EXPECT_EQ(e, error); | |
| 47 | 47 | e = getResponse("/e", boost::beast::http::verb::get); | |
| 48 | 48 | EXPECT_EQ(e, error); | |
| 49 | + // TODO: do some expectations here | ||
| 50 | + expresscpp->Stack(); | ||
| 49 | 51 | }); | |
| 50 | 52 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ TEST(StaticFileMiddleware, ServeIndexHtml) { | |||
| 36 | 36 | // ExpressJS: app.use(express.static('tmp')) | |
| 37 | 37 | expresscpp->Use(expresscpp->GetStaticFileProvider(path_to_index_html.parent_path())); | |
| 38 | 38 | ||
| 39 | - expresscpp->Listen(8080, [=]() { | ||
| 39 | + expresscpp->Listen(8081, [=]() { | ||
| 40 | 40 | // should get the index.html file | |
| 41 | 41 | auto index_html_contect_response = getResponse("/", boost::beast::http::verb::get); | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ std::string getResponse(const std::string& path, boost::beast::http::verb verb) | |||
| 20 | 20 | ||
| 21 | 21 | try { | |
| 22 | 22 | auto const host = "localhost"; | |
| 23 | - auto const port = "8080"; | ||
| 23 | + auto const port = "8081"; | ||
| 24 | 24 | // auto const target = "/"; | |
| 25 | 25 | int version = 11; | |
| 26 | 26 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments