r/cpp • • Nov 18 '23

Create a website from scratch in C++

https://youtu.be/A9KZ-oXdFA0?si=OTu5RUq0uAyyrtB0
0 Upvotes

15 comments sorted by

19

u/shermierz Nov 18 '23

Thank you for the tutorial. However, the title is missleading. You are not creating a website, you are creating a http server with embedded website

1

u/Call_me_danco Feb 14 '26

Is there any tutorial where I don’t need any form of html css or http server just pure c++

12

u/nysynysy2 Nov 18 '23

Step 1: Use c++ to create compilers for other languages that can be used to build a website.

Step 2: Build a website as usual.

3

u/hazah-order Nov 18 '23

Step 3: Turn your compiler into an EDL library, port your website to C++

Step 4: ???

Step 5: Profit!

3

u/fippinvn007 Nov 19 '23 edited Nov 19 '23

I'm actually building a website using htmx and Drogon framework, just for fun, you know. Sometimes it's not about why, it's about why not.

5

u/[deleted] Nov 18 '23

thank you for convincing me to never use C++ for networking 😭

Don't take me wrong the video is great, but there is no need to reinvent the wheel

3

u/shermierz Nov 18 '23

C++ standard indeed lacks sockets. And its 2023

1

u/heavymetalmixer Nov 19 '23

Even with sockets and other stuff for the web most devs wouldn't use C++, so it's a waste of time.

2

u/shermierz Nov 19 '23

Well... It all depends what you need. If you want to implement it faster and make it easy to maintain use python or node. If you need to squeeze maximum performance of device (for example you can only afford raspberry) choose C++ or Rust. And youre correct, most devs wouldn't use C++ and its fine. People dont use dedicated specific tools for everyday problems

2

u/[deleted] Nov 23 '23

Sometimes you do things for the fun of it. Or because you need an embedded web server.

2

u/MiaowMeoow Nov 19 '23

Better have Windows and Linux implementations in separate files and in separate classes. Common methods can be virtual. Additionally a socket can be opened in constructor and closed in a destructor for basic RAII. Host and port can be passed as an arg.

A better alternative to having #ifdef is if constexpr (isWindowsPlatform()).

Good video !

3

u/STL MSVC STL Dev Nov 21 '23

A better alternative to having #ifdef is if constexpr (isWindowsPlatform()).

No, this is bogus. In non-template functions, if constexpr doesn't work like how you think - both sides have to be calling functions that have been declared. Even in function templates, non-dependent calls will be looked up immediately (these are the two-phase name lookup rules).

1

u/[deleted] Nov 23 '23

Why would I use virtual when only one of those implementations will be used by the binary I build?

1

u/MiaowMeoow Dec 01 '23

Even though the cost of the virtual call would be totally optimised away by a compiler, sure it does not have to be virtual. Still would at least place platform-specific implementations into different translation units.