[FWN] Serve web from QRC instead of HTTP

This commit is contained in:
Nathan Hourt 2015-08-14 16:22:21 -04:00
parent 50b460f215
commit 03175707ff
3 changed files with 3 additions and 30 deletions

View file

@ -1,9 +1,6 @@
#include "BlockChain.hpp"
#include <fc/thread/thread.hpp>
#include <fc/thread/future.hpp>
#include <fc/network/http/server.hpp>
#include <fc/network/ip.hpp>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
@ -21,30 +18,6 @@ int main(int argc, char *argv[])
app.setOrganizationName("Cryptonomex, Inc.");
QtWebEngine::initialize();
fc::http::server webGuiServer;
fc::thread serverThread("HTTP server thread");
serverThread.async([&webGuiServer] {
webGuiServer.listen(fc::ip::endpoint::from_string("127.0.0.1:8080"));
webGuiServer.on_request([](const fc::http::request& request, const fc::http::server::response& response) {
QString path = QStringLiteral(":") + QString::fromStdString(request.path);
if (path.endsWith('/'))
path.append(QStringLiteral("index.html"));
QFile file(path);
if (file.exists()) {
file.open(QIODevice::ReadOnly);
auto buffer = file.readAll();
response.set_status(fc::http::reply::OK);
response.set_length(buffer.size());
response.write(buffer.data(), buffer.size());
} else {
response.set_status(fc::http::reply::NotFound);
response.set_length(18);
response.write("I can't find that.", 18);
}
});
});
qmlRegisterType<BlockChain>("Graphene.FullNode", 1, 0, "BlockChain");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

View file

@ -12,7 +12,7 @@ Window {
BlockChain {
id: blockChain
onStarted: webView.url = "http://localhost:8080"
onStarted: webView.url = "qrc:/index.html"
}
Component.onCompleted: blockChain.start()

File diff suppressed because one or more lines are too long