58be5a34f6
- 新增账号管理、有效期、启停控制与登录工作台布局 - 新增方案三叶轮转速计算及字段映射和报告支持 - 修复功率曲线断线、图例越界及方案一散点绘制 - 优化计算进度、浅色主题和当前方案提示 - 补充前端测试与部署依赖配置
72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
#include <drogon/drogon.h>
|
|
#include <trantor/utils/Logger.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "auth/AuthManager.h"
|
|
#include "controllers/AuthController.h"
|
|
#include "controllers/WindPowerController.h"
|
|
#include "utils/ResponseUtil.h"
|
|
|
|
using namespace drogon;
|
|
|
|
int main() {
|
|
// 保留任务耗时日志,便于定位上传、清洗与回传瓶颈。
|
|
trantor::Logger::setLogLevel(trantor::Logger::kInfo);
|
|
|
|
// 加载 Drogon 配置(监听端口 / CORS / 静态资源根目录)
|
|
LOG_INFO << "Loading server configuration...";
|
|
app().loadConfigFile("config/server_config.json");
|
|
if (!AuthManager::Instance().Initialize()) {
|
|
LOG_ERROR << "Failed to initialize account database";
|
|
return 1;
|
|
}
|
|
app().registerController(std::make_shared<AuthController>());
|
|
app().registerController(std::make_shared<WindPowerController>());
|
|
app().registerPreRoutingAdvice(
|
|
[](const HttpRequestPtr& req,
|
|
AdviceCallback&& stop,
|
|
AdviceChainCallback&& next) {
|
|
const std::string path = req->path();
|
|
const bool public_api = path == "/api/auth/login" ||
|
|
path == "/api/auth/logout" || path == "/api/auth/me" ||
|
|
path == "/api/system/health" || path == "/api/system/version";
|
|
if (req->method() == Options || path.rfind("/api/", 0) != 0 || public_api) {
|
|
next();
|
|
return;
|
|
}
|
|
const auto auth = AuthManager::Instance().Authenticate(
|
|
req->getCookie(AuthManager::kSessionCookie));
|
|
if (auth.status == AuthStatus::kAuthenticated) {
|
|
next();
|
|
return;
|
|
}
|
|
const bool account_abnormal = auth.status == AuthStatus::kExpired ||
|
|
auth.status == AuthStatus::kDisabled;
|
|
const auto message = account_abnormal
|
|
? "账号异常请联系管理员"
|
|
: "请先登录";
|
|
const auto code = account_abnormal ? 4 : 2;
|
|
auto response = HttpResponse::newHttpResponse();
|
|
response->setContentTypeCode(CT_APPLICATION_JSON);
|
|
response->setBody(
|
|
ResponseUtil::GenerateErrorResponse(code, message).dump());
|
|
response->setStatusCode(k401Unauthorized);
|
|
stop(response);
|
|
});
|
|
|
|
// SPA 前端路由回退:未匹配路径统一返回 index.html,交由前端路由处理
|
|
app().setCustom404Page(
|
|
HttpResponse::newFileResponse("./web/index.html", "", CT_TEXT_HTML),
|
|
false);
|
|
|
|
LOG_INFO << "wind_server starting...";
|
|
|
|
// 阻塞运行,直到收到 SIGINT/SIGTERM
|
|
app().run();
|
|
|
|
LOG_INFO << "wind_server stopped";
|
|
return 0;
|
|
}
|