From the course: Web Servers and APIs using C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Serving HTML pages

Serving HTML pages - C++ Tutorial

From the course: Web Servers and APIs using C++

Start my 1-month free trial

Serving HTML pages

- [Narrator] Route handlers look at the path passed to the website and decide which code should handle it. The only handler that we currently have is for the root route, which matches either an empty string or a lone forward slash. Let's update it to return an html file instead of a string. So, first we want to come up here, and below our current using namespace, we'll add one more. And this is gonna be for crow. And we'll come down here to the crow route and we don't need any of this, so we'll delete the old code and here we're gonna say const request... req and then we'll say response, res. And then the first thing that we're gonna do here is we're gonna say create an ifstream, name it in, and we're gonna pass to it a string, which is gonna be public /index.html. That's right here. And we're gonna pass to it an ifstream colon in because we want to read this file in. Then, we're gonna say if in, we're gonna make sure that we actually got a file handler. And if we did, we're gonna say…

Contents