Add Dockerfile, make redis feature optional, add listening address cmdline parameter

This commit is contained in:
feedc0de committed 2025-07-29 22:02:07 +02:00
1 parent 2d44560ec9
commit c10e0a17cf
7 files changed
+90 -17

No files matched your search

+23 -6
View File
@@ -23,21 +23,36 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("less_shitty_proxyjs");
QCoreApplication::setApplicationVersion("1.0");
QString identity = "test";
QHostAddress listenAddress = QHostAddress::Any;
uint16_t port = 8000;
QString identity = "test";
{
QCommandLineParser parser;
parser.setApplicationDescription("Test helper");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("identiy", QCoreApplication::translate("main", "The name of this service instance"));
parser.addPositionalArgument("listenAddr", QCoreApplication::translate("main", "The address to listen on (Can be \"Any\" \"Localhost\" or any valid ip address)."));
parser.addPositionalArgument("port", QCoreApplication::translate("main", "The port to listen on (will only listen on localhost)."));
parser.addPositionalArgument("identiy", QCoreApplication::translate("main", "The name of this service instance"));
parser.process(app);
const auto &args = parser.positionalArguments();
if (args.size() > 0)
identity = args.first();
{
if (const auto &str = args.first(); str == "Any")
listenAddress = QHostAddress::Any;
else if (str == "AnyIPv4")
listenAddress = QHostAddress::AnyIPv4;
else if (str == "AnyIPv6")
listenAddress = QHostAddress::AnyIPv6;
else if (str == "LocalHost")
listenAddress = QHostAddress::LocalHost;
else if (str == "LocalHostIPv6")
listenAddress = QHostAddress::LocalHostIPv6;
else
listenAddress = QHostAddress{str};
}
if (args.size() > 1)
{
bool ok;
@@ -48,6 +63,8 @@ int main(int argc, char *argv[])
return -1;
}
}
if (args.size() > 2)
identity = args.at(2);
}
qSetMessagePattern(QString{"%{time dd.MM.yyyy HH:mm:ss.zzz} %0 "
@@ -64,9 +81,9 @@ int main(int argc, char *argv[])
WebServer server{identity, QString{"http://localhost:%0"}.arg(port)};
QTcpServer tcpServer;
if (!tcpServer.listen(QHostAddress::LocalHost, port))
if (!tcpServer.listen(listenAddress, port))
{
qCritical("failed to start listening on port %hu: %s", port, qPrintable(tcpServer.errorString()));
qCritical("failed to start listening on addr %s port %hu: %s", qPrintable(listenAddress.toString()), port, qPrintable(tcpServer.errorString()));
return -1;
}
@@ -76,7 +93,7 @@ int main(int argc, char *argv[])
return -2;
}
qDebug() << "server started";
qDebug() << "server started on" << listenAddress << "port" << port;
auto result = app.exec();
qDebug() << "bey bey!";