peerplays_migrated/programs/full_web_node/main.cpp

54 lines
1.8 KiB
C++
Raw Normal View History

2015-08-12 18:56:33 +00:00
#include "BlockChain.hpp"
#include <fc/thread/thread.hpp>
2015-08-12 18:56:33 +00:00
#include <fc/thread/future.hpp>
#include <fc/network/http/server.hpp>
#include <fc/network/ip.hpp>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
2015-08-12 18:56:33 +00:00
#include <QQmlContext>
#include <QtWebEngine>
#include <QtQml>
int main(int argc, char *argv[])
{
fc::thread::current().set_name("main");
QGuiApplication app(argc, argv);
app.setApplicationName("Graphene Client");
app.setApplicationDisplayName(app.applicationName());
app.setOrganizationDomain("cryptonomex.org");
app.setOrganizationName("Cryptonomex, Inc.");
QtWebEngine::initialize();
2015-08-12 18:56:33 +00:00
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) {
2015-08-14 19:26:46 +00:00
QString path = QStringLiteral(":") + QString::fromStdString(request.path);
2015-08-12 18:56:33 +00:00
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);
}
});
});
2015-08-14 19:09:21 +00:00
qmlRegisterType<BlockChain>("Graphene.FullNode", 1, 0, "BlockChain");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
2015-08-14 19:09:21 +00:00
return app.exec();
}