CrowCpp / Crow

A Fast and Easy to use microframework for the web.
https://crowcpp.org
Other
3.3k stars 364 forks source link

Setting CROW_DISABLE_STATIC_DIR disables the blueprint paths all together #941

Open morphonedev opened 1 week ago

morphonedev commented 1 week ago

Description Setting the CROW_DISABLE_STATIC_DIR define, e.g. via target_compile_definitions(Crow INTERFACE CROW_DISABLE_STATIC_DIR) in the CMakeLists.txt, disables all blueprint paths.

Steps to reproduce the behavior:

  1. Set the define CROW_DISABLE_STATIC_DIR
  2. Compile the example_blueprint.cpp
  3. Run it and try to access any blueprint route

To make the error more apparent

changing the line: app.loglevel(crow::LogLevel::Debug).port(18080).run(); to

    auto future = app.loglevel(crow::LogLevel::Debug).port(18080).run_async();
    app.debug_print();
    future.get();

clearly shows no routes at all.

(2024-11-11 22:54:53) [DEBUG   ] Routing:
(2024-11-11 22:54:53) [INFO    ] Crow/master server is running at http://0.0.0.0:18080 using 2 threads
(2024-11-11 22:54:53) [INFO    ] Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.
(2024-11-11 22:54:53) [DEBUG   ] 0000026706D1B590 {0} queue length: 1

Expected behavior The non static blueprint routes should still be available.

Analysis

It looks like the code

#ifndef CROW_DISABLE_STATIC_DIR
            add_blueprint();
            add_static_dir();
#endif

in app.h is the only position where addblueprint() and within it `router.validate_bp();` gets called.

One possible fix would be to move router_.validate_bp(); into the Crow::validate method.