| 28 | using stefanfrings::StaticFileController; |
| 29 | |
| 30 | void YACReaderHttpServer::start(quint16 port) |
| 31 | { |
| 32 | // Initialize the core application |
| 33 | QCoreApplication *app = QCoreApplication::instance(); |
| 34 | QString configFileName = YACReader::getSettingsPath() + "/" + QCoreApplication::applicationName() + ".ini"; |
| 35 | |
| 36 | Static::yacreaderSessionStore = new YACReaderHttpSessionStore(app); |
| 37 | |
| 38 | // Configure static file controller |
| 39 | auto fileSettings = new QSettings(configFileName, QSettings::IniFormat, app); |
| 40 | fileSettings->beginGroup("docroot"); |
| 41 | |
| 42 | QString basedocroot = "./server/docroot"; |
| 43 | QString docroot; |
| 44 | |
| 45 | #if defined Q_OS_UNIX && !defined Q_OS_MACOS |
| 46 | QFileInfo configFile(QString(DATADIR) + "/yacreader"); |
| 47 | docroot = QFileInfo(QString(DATADIR) + "/yacreader", basedocroot).absoluteFilePath(); |
| 48 | #else |
| 49 | QFileInfo configFile(QCoreApplication::applicationDirPath()); |
| 50 | docroot = QFileInfo(QCoreApplication::applicationDirPath(), basedocroot).absoluteFilePath(); |
| 51 | #endif |
| 52 | |
| 53 | // The WebUI is shipped with the application, so its document root must |
| 54 | // follow the currently running binary. Persisting the generated path made |
| 55 | // it point to stale build and installation directories after an upgrade. |
| 56 | // TODO: do we really want to keep using this setting at all? |
| 57 | fileSettings->setValue("path", docroot); |
| 58 | |
| 59 | Static::staticFileController = new StaticFileController(fileSettings, app); |
| 60 | |
| 61 | // Configure and start the TCP listener |
| 62 | qDebug("ServiceHelper: Starting service"); |
| 63 | auto listenerSettings = new QSettings(configFileName, QSettings::IniFormat, app); |
| 64 | listenerSettings->beginGroup("listener"); |
| 65 | |
| 66 | if (listenerSettings->value("maxRequestSize").isNull()) |
| 67 | listenerSettings->setValue("maxRequestSize", "32000000"); |
| 68 | |
| 69 | if (listenerSettings->value("maxMultiPartSize").isNull()) |
| 70 | listenerSettings->setValue("maxMultiPartSize", "32000000"); |
| 71 | |
| 72 | if (listenerSettings->value("cleanupInterval").isNull()) |
| 73 | listenerSettings->setValue("cleanupInterval", 10000); |
| 74 | |
| 75 | if (listenerSettings->value("maxThreads").isNull()) |
| 76 | listenerSettings->setValue("maxThreads", 1000); |
| 77 | |
| 78 | if (listenerSettings->value("minThreads").isNull()) |
| 79 | listenerSettings->setValue("minThreads", 50); |
| 80 | |
| 81 | if (listenerSettings->value("port").isNull()) |
| 82 | listenerSettings->setValue("port", 8080); |
| 83 | |
| 84 | // start with a temporary port |
| 85 | if (port != 0) { |
| 86 | // cache saved port |
| 87 | if (!listenerSettings->contains("cachedPort")) { |
no test coverage detected