mirror of https://github.com/nymea/nymea.git
Fix the webserver for serving static files
parent
2ca4b2f32f
commit
2f17a86506
|
|
@ -264,7 +264,7 @@ void ServerManager::webServerConfigurationChanged(const QString &id)
|
|||
qDebug(dcServerManager()) << "Restarting Web server for" << config.address << config.port << "SSL" << (config.sslEnabled ? "enabled" : "disabled") << "Authentication" << (config.authenticationEnabled ? "enabled" : "disabled");
|
||||
unregisterZeroConfService(id, "http");
|
||||
server->stopServer();
|
||||
server->reconfigureServer(config);
|
||||
server->setConfiguration(config);
|
||||
} else {
|
||||
qDebug(dcServerManager()) << "Received a Web Server config change event but don't have a Web Server instance for it. Creating new WebServer instance on" << config.address.toString() << config.port << "(SSL:" << config.sslEnabled << ")";
|
||||
server = new WebServer(config, m_sslConfiguration, this);
|
||||
|
|
|
|||
|
|
@ -163,22 +163,6 @@ void TcpServer::onDataAvailable(QSslSocket * socket, const QByteArray &data)
|
|||
emit dataAvailable(clientId, data);
|
||||
}
|
||||
|
||||
|
||||
/*! Returns true if this \l{TcpServer} could be reconfigured with the given \a config. */
|
||||
void TcpServer::reconfigureServer(const ServerConfiguration &config)
|
||||
{
|
||||
if (configuration().address == config.address &&
|
||||
configuration().port == config.port &&
|
||||
configuration().sslEnabled == config.sslEnabled &&
|
||||
configuration().authenticationEnabled == config.authenticationEnabled &&
|
||||
m_server->isListening())
|
||||
return;
|
||||
|
||||
stopServer();
|
||||
setConfiguration(config);
|
||||
startServer();
|
||||
}
|
||||
|
||||
/*! Sets the name of this server to the given \a serverName. */
|
||||
void TcpServer::setServerName(const QString &serverName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ private slots:
|
|||
void onError(QAbstractSocket::SocketError error);
|
||||
|
||||
public slots:
|
||||
void reconfigureServer(const ServerConfiguration &configuration);
|
||||
void setServerName(const QString &serverName) override;
|
||||
bool startServer() override;
|
||||
bool stopServer() override;
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ void WebServer::readClient()
|
|||
return;
|
||||
|
||||
QFile file(path);
|
||||
if (file.open(QFile::ReadOnly | QFile::Truncate)) {
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
qCDebug(dcWebServer()) << "Load file" << file.fileName();
|
||||
HttpReply *reply = HttpReply::createSuccessReply();
|
||||
|
||||
|
|
@ -487,7 +487,6 @@ void WebServer::onDisconnected()
|
|||
if (client->address() == socket->peerAddress()) {
|
||||
client->removeConnection(socket);
|
||||
if (client->connections().isEmpty()) {
|
||||
qCDebug(dcWebServer()) << "Delete client" << client->address().toString();
|
||||
m_webServerClients.removeAll(client);
|
||||
client->deleteLater();
|
||||
}
|
||||
|
|
@ -549,19 +548,9 @@ void WebServer::onAsyncReplyFinished()
|
|||
*
|
||||
* \sa WebServerConfiguration
|
||||
*/
|
||||
void WebServer::reconfigureServer(const WebServerConfiguration &config)
|
||||
void WebServer::setConfiguration(const WebServerConfiguration &config)
|
||||
{
|
||||
if (m_configuration.address == config.address &&
|
||||
m_configuration.port == config.port &&
|
||||
m_configuration.sslEnabled == config.sslEnabled &&
|
||||
m_configuration.authenticationEnabled == config.authenticationEnabled &&
|
||||
m_configuration.publicFolder == config.publicFolder &&
|
||||
isListening())
|
||||
return;
|
||||
|
||||
stopServer();
|
||||
m_configuration = config;
|
||||
startServer();
|
||||
}
|
||||
|
||||
/*! Sets the server name to the given \a serverName. */
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ private slots:
|
|||
void onAsyncReplyFinished();
|
||||
|
||||
public slots:
|
||||
void reconfigureServer(const WebServerConfiguration &config);
|
||||
void setConfiguration(const WebServerConfiguration &config);
|
||||
void setServerName(const QString &serverName);
|
||||
bool startServer();
|
||||
bool stopServer();
|
||||
|
|
|
|||
|
|
@ -197,25 +197,6 @@ void WebSocketServer::onPing(quint64 elapsedTime, const QByteArray &payload)
|
|||
qCDebug(dcWebSocketServer) << "Ping response from" << clientId.toString() << elapsedTime << payload;
|
||||
}
|
||||
|
||||
|
||||
/*! Returns true if this \l{WebSocketServer} could be reconfigured with the given \a config. */
|
||||
void WebSocketServer::reconfigureServer(const ServerConfiguration &config)
|
||||
{
|
||||
if (configuration() == config && m_server->isListening()) {
|
||||
qCDebug(dcWebSocketServer()) << "Configuration unchanged. Not restarting the server.";
|
||||
return;
|
||||
}
|
||||
|
||||
stopServer();
|
||||
qCDebug(dcWebSocketServer()) << "Stopped server for reconfiguration.";
|
||||
|
||||
setConfiguration(config);
|
||||
|
||||
// Start server with new configuration
|
||||
qCDebug(dcWebSocketServer()) << "Restart server with new configuration.";
|
||||
startServer();
|
||||
}
|
||||
|
||||
/*! Sets the server name to the given \a serverName. */
|
||||
void WebSocketServer::setServerName(const QString &serverName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ private slots:
|
|||
void onPing(quint64 elapsedTime, const QByteArray & payload);
|
||||
|
||||
public slots:
|
||||
void reconfigureServer(const ServerConfiguration &config);
|
||||
void setServerName(const QString &serverName) override;
|
||||
bool startServer() override;
|
||||
bool stopServer() override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue