chore: init frontend+backend skeleton
这个提交包含在:
46
backend/CMakeLists.txt
普通文件
46
backend/CMakeLists.txt
普通文件
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(csp_backend LANGUAGES CXX)
|
||||
|
||||
# Drogon 1.8.x on Ubuntu still uses legacy CMake commands.
|
||||
cmake_policy(SET CMP0153 OLD)
|
||||
|
||||
find_package(Drogon CONFIG REQUIRED)
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
|
||||
add_library(csp_core
|
||||
src/version.cc
|
||||
)
|
||||
|
||||
target_include_directories(csp_core PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
# SQLite will be used via Drogon DB client in later iterations.
|
||||
|
||||
add_executable(csp_server
|
||||
src/main.cc
|
||||
src/health_controller.cc
|
||||
)
|
||||
|
||||
target_include_directories(csp_server PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(csp_server PRIVATE
|
||||
Drogon::Drogon
|
||||
csp_core
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
add_executable(csp_tests
|
||||
tests/test_main.cc
|
||||
tests/version_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(csp_tests PRIVATE
|
||||
Catch2::Catch2WithMain
|
||||
csp_core
|
||||
)
|
||||
|
||||
include(CTest)
|
||||
add_test(NAME csp_tests COMMAND csp_tests)
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <drogon/HttpController.h>
|
||||
|
||||
namespace csp {
|
||||
|
||||
class HealthController : public drogon::HttpController<HealthController> {
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
ADD_METHOD_TO(HealthController::health, "/api/health", drogon::Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
void health(const drogon::HttpRequestPtr& req,
|
||||
std::function<void(const drogon::HttpResponsePtr&)>&& callback);
|
||||
};
|
||||
|
||||
} // namespace csp
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace csp {
|
||||
|
||||
constexpr const char* kVersion = "0.1.0";
|
||||
|
||||
} // namespace csp
|
||||
18
backend/src/health_controller.cc
普通文件
18
backend/src/health_controller.cc
普通文件
@@ -0,0 +1,18 @@
|
||||
#include "csp/health_controller.h"
|
||||
|
||||
#include "csp/version.h"
|
||||
|
||||
namespace csp {
|
||||
|
||||
void HealthController::health(
|
||||
const drogon::HttpRequestPtr& /*req*/,
|
||||
std::function<void(const drogon::HttpResponsePtr&)>&& callback) {
|
||||
auto json = Json::Value{};
|
||||
json["ok"] = true;
|
||||
json["version"] = kVersion;
|
||||
auto resp = drogon::HttpResponse::newHttpJsonResponse(json);
|
||||
resp->setStatusCode(drogon::k200OK);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
} // namespace csp
|
||||
15
backend/src/main.cc
普通文件
15
backend/src/main.cc
普通文件
@@ -0,0 +1,15 @@
|
||||
#include <drogon/drogon.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
// Basic defaults. Will be moved to config-driven later.
|
||||
drogon::app()
|
||||
.addListener("0.0.0.0", 8080)
|
||||
.setThreadNum(4);
|
||||
|
||||
LOG_INFO << "csp_server starting at http://0.0.0.0:8080";
|
||||
drogon::app().run();
|
||||
return 0;
|
||||
}
|
||||
5
backend/src/version.cc
普通文件
5
backend/src/version.cc
普通文件
@@ -0,0 +1,5 @@
|
||||
#include "csp/version.h"
|
||||
|
||||
namespace csp {
|
||||
// Keep translation unit for future expansion.
|
||||
} // namespace csp
|
||||
1
backend/tests/test_main.cc
普通文件
1
backend/tests/test_main.cc
普通文件
@@ -0,0 +1 @@
|
||||
// Intentionally empty: Catch2WithMain provides main().
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "csp/version.h"
|
||||
|
||||
TEST_CASE("version is non-empty") {
|
||||
REQUIRE(csp::kVersion != nullptr);
|
||||
REQUIRE(std::string(csp::kVersion).size() > 0);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户