1

I have been following this example in the "Getting Started" page on Crow's website but the page is blank after compiling on Xcode.

**/main.cpp**

#include "crow.h"
//#include "crow_all.h"

int main()
{
    crow::SimpleApp app;

    //define your endpoint at the root directory
    CROW_ROUTE(app, "/")([](){
        auto page = crow::mustache::load_text("fancypage.html");
        return page;
    });

    app.port(18080).multithreaded().run();
}

I followed the instructions provided regarding adding "fancypage.html" in the Crow project, however, I still receive the error "Template "fancypage.html" not found." Responses to a similar question on stack overflow pointed out that the problem may be related to loading static files with Crow. I tried one user's response of using the absolute path instead of the relative path which did not work. I also tried using the Crow function "set_static_file_info" as shown in the following:

CROW_ROUTE(app, "/")
([](const crow::request&, crow::response& res) {
    //replace fancypage.html with your file path
    res.set_static_file_info("fancypage.html");
    res.end();
});

but I received "Error 404" on my page.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • the "templates" directory needs to be in your active directory, did you make sure that xcode was running your application in the same directory as your templates directory? – Farook Al-Sammarraie Jun 27 '22 at 19:15
  • Thanks for the response. Yes, the "template" folder containing the HTML document is in my active directory. –  Jun 28 '22 at 20:25
  • I tried the "set_static_file_info_unsafe" with the absolute path of the HTML document and it worked. This is probably not the best solution though. –  Jun 28 '22 at 20:28
  • if an absolute path is working then the problem most likely is related to the directory the executable is running in. you can add `std::cout << std::system("pwd") << std::endl;` to print where that is. – Farook Al-Sammarraie Jun 30 '22 at 02:55

0 Answers0