diff --git a/Dockerfile b/Dockerfile index f32f943..15ccff0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ENV TZ=Europe/London WORKDIR /build RUN apt update && apt install -y --no-install-recommends \ git g++ make pkg-config libtool ca-certificates \ - libyaml-perl libtemplate-perl libssl-dev zlib1g-dev \ + libyaml-perl libtemplate-perl libregexp-grammars-perl libssl-dev zlib1g-dev \ liblmdb-dev libflatbuffers-dev libsecp256k1-dev \ libzstd-dev diff --git a/Makefile b/Makefile index e457185..cdbb728 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,8 @@ include golpe/rules.mk LDLIBS += -lsecp256k1 -lzstd INCS += -Iexternal/negentropy/cpp + +build/StrfryTemplates.h: $(shell find src/tmpls/ -type f -name '*.tmpl') + perl golpe/external/templar/templar.pl src/tmpls/ strfrytmpl $@ + +src/apps/relay/RelayWebsocket.o: build/StrfryTemplates.h diff --git a/README.md b/README.md index af96ddf..ab5c7c3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Either the full set of messages in the DB can be synced, or the results of one o A C++20 compiler is required, along with a few other common dependencies. On Debian/Ubuntu use these commands: - sudo apt install -y git build-essential libyaml-perl libtemplate-perl libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev + sudo apt install -y git build-essential libyaml-perl libtemplate-perl libregexp-grammars-perl libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev git submodule update --init make setup-golpe make -j4 diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 3349257..21ef104 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -42,7 +42,7 @@ While you wait for your server to provision, go to your DNS provider and point a cd strfry # Install complication dependencies - sudo apt install -y git build-essential libyaml-perl libtemplate-perl libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev + sudo apt install -y git build-essential libyaml-perl libtemplate-perl libregexp-grammars-perl libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev # Build it git submodule update --init diff --git a/golpe b/golpe index 2c40f2d..ef252ab 160000 --- a/golpe +++ b/golpe @@ -1 +1 @@ -Subproject commit 2c40f2dc26d31920d7ddde4e692d48ad9ffb9435 +Subproject commit ef252ab9979319138d001499723f997b000d4534 diff --git a/src/apps/relay/RelayWebsocket.cpp b/src/apps/relay/RelayWebsocket.cpp index b295f4f..75c974c 100644 --- a/src/apps/relay/RelayWebsocket.cpp +++ b/src/apps/relay/RelayWebsocket.cpp @@ -1,5 +1,6 @@ #include "RelayServer.h" +#include "StrfryTemplates.h" #include "app_git_version.h" @@ -47,15 +48,16 @@ void RelayServer::runWebsocket(ThreadPool::Thread &thr) { tempBuf.reserve(cfg().events__maxEventSize + MAX_SUBID_SIZE + 100); + tao::json::value supportedNips = tao::json::value::array({ 1, 2, 4, 9, 11, 12, 16, 20, 22, 28, 33, 40 }); - auto getServerInfoHttpResponse = [ver = uint64_t(0), rendered = std::string("")]() mutable { + auto getServerInfoHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable { if (ver != cfg().version()) { rendered = preGenerateHttpResponse("application/json", tao::json::to_string(tao::json::value({ { "name", cfg().relay__info__name }, { "description", cfg().relay__info__description }, { "pubkey", cfg().relay__info__pubkey }, { "contact", cfg().relay__info__contact }, - { "supported_nips", tao::json::value::array({ 1, 2, 4, 9, 11, 12, 15, 16, 20, 22, 28, 33, 40 }) }, + { "supported_nips", supportedNips }, { "software", "git+https://github.com/hoytech/strfry.git" }, { "version", APP_GIT_VERSION }, }))); @@ -65,7 +67,19 @@ void RelayServer::runWebsocket(ThreadPool::Thread &thr) { return std::string_view(rendered); // memory only valid until next call }; - const std::string defaultHttpResponse = preGenerateHttpResponse("text/plain", "Please use a Nostr client to connect."); + auto getLandingPageHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable { + if (ver != cfg().version()) { + struct { + std::string supportedNips; + std::string version; + } ctx = { tao::json::to_string(supportedNips), APP_GIT_VERSION }; + + rendered = preGenerateHttpResponse("text/html", ::strfrytmpl::landing(ctx).str); + ver = cfg().version(); + } + + return std::string_view(rendered); // memory only valid until next call + }; @@ -87,7 +101,8 @@ void RelayServer::runWebsocket(ThreadPool::Thread &thr) { auto info = getServerInfoHttpResponse(); res->write(info.data(), info.size()); } else { - res->write(defaultHttpResponse.data(), defaultHttpResponse.size()); + auto landing = getLandingPageHttpResponse(); + res->write(landing.data(), landing.size()); } }); diff --git a/src/tmpls/landing.tmpl b/src/tmpls/landing.tmpl new file mode 100644 index 0000000..e6be90c --- /dev/null +++ b/src/tmpls/landing.tmpl @@ -0,0 +1,160 @@ + + + + + + +
+ + Please use a Nostr client to connect. +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Relay
Name$(cfg().relay__info__name)
Description$(cfg().relay__info__description)
Pubkey$(cfg().relay__info__pubkey)
Contact$(cfg().relay__info__contact)
+ + + + + + + + + + + + + + + + + + + + +
Server Software
Softwarestrfry
Version$(ctx.version)
Supported NIPs$(ctx.supportedNips)
+ +