Initial commit

This commit is contained in:
feedc0de committed 2025-07-16 20:25:01 +02:00
commit ceba2958fa
16 files changed
+720

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include "webserver.h"
#include <QTcpServer>
#include <QDebug>
int main(int argc, char *argv[])
{
qSetMessagePattern("%{time dd.MM.yyyy HH:mm:ss.zzz} "
"["
"%{if-debug}D%{endif}"
"%{if-info}I%{endif}"
"%{if-warning}W%{endif}"
"%{if-critical}C%{endif}"
"%{if-fatal}F%{endif}"
"] "
"%{function}(): "
"%{message}");
QCoreApplication app{argc, argv};
QCoreApplication::setApplicationName("less_shitty_proxyjs");
QCoreApplication::setApplicationVersion("1.0");
QString identity = "test";
uint16_t port = 8000;
{
QCommandLineParser parser;
parser.setApplicationDescription("Test helper");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("identiy", QCoreApplication::translate("main", "The name of this service instance"));
parser.addPositionalArgument("port", QCoreApplication::translate("main", "The port to listen on (will only listen on localhost)."));
parser.process(app);
const auto &args = parser.positionalArguments();
if (args.size() > 0)
identity = args.first();
if (args.size() > 1)
{
bool ok;
port = args.at(1).toInt(&ok);
if (!ok)
{
qCritical("could not parse port: %s", qPrintable(args.at(1)));
return -1;
}
}
}
qSetMessagePattern(QString{"%{time dd.MM.yyyy HH:mm:ss.zzz} %0 "
"["
"%{if-debug}D%{endif}"
"%{if-info}I%{endif}"
"%{if-warning}W%{endif}"
"%{if-critical}C%{endif}"
"%{if-fatal}F%{endif}"
"] "
"%{function}(): "
"%{message}"}.arg(identity));
WebServer server{identity, QString{"http://localhost:%0"}.arg(port)};
QTcpServer tcpServer;
if (!tcpServer.listen(QHostAddress::LocalHost, port))
{
qCritical("failed to start listening on port %hu: %s", port, qPrintable(tcpServer.errorString()));
return -1;
}
if (!server.bind(&tcpServer))
{
qCritical("failed to webserver on socket!");
return -2;
}
qDebug() << "server started";
auto result = app.exec();
qDebug() << "bey bey!";
return result;
}