Files
Renderive/web_server/main.cpp
T
2026-08-11 06:21:51 +08:00

30 lines
1.0 KiB
C++

#include "Web_Server.h"
#include <charconv>
#include <cstdint>
#include <filesystem>
#include <iostream>
#include <string_view>
namespace {
std::uint16_t parse_port(int argc, char** argv) {
constexpr std::uint16_t default_port = 8848;
if (argc != 3 || std::string_view(argv[1]) != "--port")
return default_port;
unsigned value{};
const std::string_view text(argv[2]);
const auto [end, error] = std::from_chars(text.data(), text.data() + text.size(), value);
if (error != std::errc{} || end != text.data() + text.size() || value == 0 || value > 65535) {
std::cerr << "Invalid port: " << text << '\n';
return 0;
}
return static_cast<std::uint16_t>(value);
}
} // namespace
int main(int argc, char** argv) {
const std::uint16_t port = parse_port(argc, argv);
if (port == 0)
return 2;
std::cout << "http://127.0.0.1:8848" << std::endl;
const std::filesystem::path executable = std::filesystem::absolute(argv[0]);
return renderive::web::run_web_server(port, executable.parent_path());
}