69 lines
2.0 KiB
C++
69 lines
2.0 KiB
C++
|
|
#ifndef VRPMDV_STATICCONTROLLER_HPP
|
|
#define VRPMDV_STATICCONTROLLER_HPP
|
|
|
|
#include "oatpp/web/server/api/ApiController.hpp"
|
|
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
|
|
#include "oatpp/core/macro/codegen.hpp"
|
|
#include "oatpp/core/macro/component.hpp"
|
|
#include <fstream>
|
|
|
|
#include OATPP_CODEGEN_BEGIN(ApiController) //<- Begin Codegen
|
|
|
|
class StaticController : public oatpp::web::server::api::ApiController {
|
|
private:
|
|
oatpp::String m_resDir = "./";
|
|
|
|
public:
|
|
StaticController(const std::shared_ptr<ObjectMapper>& objectMapper)
|
|
: oatpp::web::server::api::ApiController(objectMapper)
|
|
{}
|
|
public:
|
|
|
|
static std::shared_ptr<StaticController> createShared(
|
|
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper) // Inject objectMapper component here as default parameter
|
|
){
|
|
return std::make_shared<StaticController>(objectMapper);
|
|
}
|
|
|
|
ENDPOINT("GET", "/", root) {
|
|
// const char* html =
|
|
// "<html lang='en'>"
|
|
// " <head>"
|
|
// " <meta charset=utf-8/>"
|
|
// " </head>"
|
|
// " <body>"
|
|
// " <p>Hello CRUD example project!</p>"
|
|
// " <a href='swagger/ui'>Checkout Swagger-UI page</a>"
|
|
// " </body>"
|
|
// "</html>";
|
|
|
|
oatpp::String html;// = loadFromFile("index.html");
|
|
const oatpp::String htmlsend = html.loadFromFile("./webui/index.html");
|
|
auto response = createResponse(Status::CODE_200, htmlsend);
|
|
response->putHeader(Header::CONTENT_TYPE, "text/html");
|
|
return response;
|
|
}
|
|
|
|
// oatpp::String loadFromFile(const char* fileName) {
|
|
|
|
// auto fullFilename = m_resDir + fileName;
|
|
|
|
// std::ifstream file (fullFilename->c_str(), std::ios::in|std::ios::binary|std::ios::ate);
|
|
|
|
// if (file.is_open()) {
|
|
|
|
// auto result = oatpp::String((v_int32) file.tellg());
|
|
// file.seekg(0, std::ios::beg);
|
|
// file.read((char*)result->data(), result->size());
|
|
// file.close();
|
|
// return result;
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
#include OATPP_CODEGEN_END(ApiController) //<- End Codegen
|
|
|
|
#endif //VRPMDV_STATICCONTROLLER_HPP
|