Closed asra-baig closed 5 years ago
Hello, I was able to view an html page as html when I would type it in main.cpp but after creating an index.html file and streaming it in, it is rendering as plain text on my browser.
This is my main.cpp:
#include "crow_all.h" using namespace std; using namespace crow; int main(int argc, char* argv[]) { crow::SimpleApp app; CROW_ROUTE(app, "/") ([](const request &req, response &res){ ifstream in("../public/index.html", ifstream::in); if(in) { ostringstream contents; contents << in.rdbuf(); in.close(); res.write(contents.str()); } else { res.write("Not found"); } res.end(); }); char* port = getenv("PORT"); uint16_t iPort = static_cast<uint16_t>(port != NULL? stoi(port): 18080); cout << "PORT = " << iPort << "\n"; app.port(iPort).multithreaded().run(); }
And this is my index.html: <!DOCKTYPE html>
Was able to view it as html by setting the response header to "text/html": set_header("Content-Type", "text/html");
Hello, I was able to view an html page as html when I would type it in main.cpp but after creating an index.html file and streaming it in, it is rendering as plain text on my browser.
This is my main.cpp:
And this is my index.html: <!DOCKTYPE html>
H1, Crow.