Add some debug information
FossilOrigin-Name: 9f05b05915fb5c06d571c4d9f03574f7a983399481405665d73436e025c38f9e
This commit is contained in:
parent
ab9febe035
commit
677e46e341
7 changed files with 51 additions and 14 deletions
|
@ -78,7 +78,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||
else()
|
||||
# Some asserts are in the code...
|
||||
add_definitions(-DNDEBUG)
|
||||
add_compile_options(-Wall -Wno-used-function -Wno-reorder -O2)
|
||||
add_compile_options(-Wall -Wno-unused-function -Wno-reorder -O2)
|
||||
endif()
|
||||
|
||||
set(WORMHOLE_INCLUDE_DIRS
|
||||
|
|
|
@ -149,6 +149,12 @@ namespace
|
|||
MHD_RESPMEM_MUST_COPY);
|
||||
|
||||
MHD_add_response_header(response, "Content-Type", MIME::mime_to_str(resp->mimetype).data());
|
||||
|
||||
// Useful for testing with frontends
|
||||
#ifndef NDEBUG
|
||||
MHD_add_response_header(response, "Access-Control-Allow-Origin", "*");
|
||||
#endif
|
||||
|
||||
// HTTP::Code works for MHD already since it's just int's that represent the HTTP response codes
|
||||
ret = MHD_queue_response(conn, resp->code, response);
|
||||
|
||||
|
|
34
src/main.cpp
34
src/main.cpp
|
@ -65,7 +65,8 @@ void init_routes(const std::unique_ptr<HTTP::Server>& server)
|
|||
#endif // MODULE_FCGI
|
||||
}
|
||||
|
||||
int start_wormhole()
|
||||
int
|
||||
start_wormhole()
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
||||
|
@ -147,10 +148,9 @@ int start_wormhole()
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
inline void
|
||||
load_configs()
|
||||
{
|
||||
int res = EXIT_SUCCESS;
|
||||
|
||||
// Initialize config
|
||||
// Try XDG config, then HOME
|
||||
std::filesystem::path xdgpath;
|
||||
|
@ -177,9 +177,31 @@ int main(int argc, char** argv)
|
|||
if (!found)
|
||||
{
|
||||
std::cerr << " !! Couldn't find a config file for Wormhole, "
|
||||
"this is required to function." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
"this is required to function. Possible paths include: \n";
|
||||
for (auto path: pths)
|
||||
{
|
||||
std::cerr << " - " << path.generic_string() << "\n";
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
int res = EXIT_SUCCESS;
|
||||
|
||||
load_configs();
|
||||
|
||||
// Notify user if in debug mode
|
||||
#ifndef NDEBUG
|
||||
std::cout << " !! Notice: You compiled with " RED " DEBUG MODE " RESET " which "
|
||||
"means that some debug features are enabled, like full CORS request access."
|
||||
<< std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
// Start wormhole as is, no arguments needed
|
||||
if (argc <= 1)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
add_library(wormhole_masto_api_module
|
||||
mastoapi.cpp apps.cpp)
|
||||
mastoapi.cpp
|
||||
instance.cpp
|
||||
apps.cpp)
|
||||
include_directories(wormhole_masto_api_module ${WORMHOLE_INCLUDE_DIRS})
|
||||
target_link_libraries(wormhole_masto_api_module wormhole_lib)
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "instance.h"
|
||||
|
||||
#include <utility>
|
||||
#include "http/response.h"
|
||||
#include "jsonhelper.h"
|
||||
#include "route_args.h"
|
||||
#include "http/mime.h"
|
||||
|
||||
|
@ -20,19 +22,19 @@ Route::MastoAPI::get_instance(std::any& args,
|
|||
rjson::Document root(rjson::kObjectType);
|
||||
rjson::Document::AllocatorType& a = root.GetAllocator();
|
||||
|
||||
root.AddMember("website", rjson::Value())
|
||||
root.AddMember("name", "test", a);
|
||||
|
||||
return HTTP::Response{ rjson::to_string(root), HTTP::MIME::JSON };
|
||||
}
|
||||
|
||||
void
|
||||
Protocol::MastoAPI::init_instance_info(HTTP::Server* server)
|
||||
Protocol::MastoAPI::init_masto_instance(HTTP::Server* server)
|
||||
{
|
||||
server->add_route({
|
||||
HTTP::Request{
|
||||
HTTP::Request::Type::GET,
|
||||
"/api/v1/instance",
|
||||
HTTP::MIME::Mimetypes
|
||||
HTTP::MIME::Mimetypes::JSON,
|
||||
},
|
||||
Route::MastoAPI::get_instance
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Protocol
|
|||
namespace MastoAPI
|
||||
{
|
||||
void
|
||||
init_instance_info(HTTP::Server* server);
|
||||
init_masto_instance(HTTP::Server* server);
|
||||
}
|
||||
}
|
||||
#endif // INSTANCE_H
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
#include "http/httpserver.h"
|
||||
#include "http/error_response.h"
|
||||
#include "http/request.h"
|
||||
#include "apps.h"
|
||||
#include "types/user.h"
|
||||
#include "logger.h"
|
||||
#include "jsonhelper.h"
|
||||
#include "route_args.h"
|
||||
|
||||
// Routes to be loaded here
|
||||
#include "apps.h"
|
||||
#include "instance.h"
|
||||
|
||||
using namespace Protocol;
|
||||
using namespace std::string_literals;
|
||||
|
||||
|
@ -33,9 +36,11 @@ Route::MastoAPI::test(std::any& args,
|
|||
return HTTP::Response{ "{\"test\":\"succeeded1\"}", HTTP::MIME::JSON };
|
||||
}
|
||||
|
||||
void MastoAPI::init_masto_api(HTTP::Server* server)
|
||||
void
|
||||
MastoAPI::init_masto_api(HTTP::Server* server)
|
||||
{
|
||||
server->add_route({{HTTP::Request::Type::GET, "/api/v1/wormhole_test"}, Route::MastoAPI::test});
|
||||
|
||||
init_masto_apps(server);
|
||||
init_masto_instance(server);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue