upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/components/wisp_relay/nip11_relay.c
blob: 4e1df3772554f567e208e868a327745fd55d922a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "nip11_relay.h"
#include <string.h>

static const char *NIP11_JSON =
"{"
  "\"name\":\"TollGate Relay\","
  "\"description\":\"Local Nostr relay with 21-day TTL and negentropy sync\","
  "\"pubkey\":\"\","
  "\"contact\":\"\","
  "\"supported_nips\":[1,9,11,20,40,77],"
  "\"software\":\"https://github.com/nicobao/esp32-tollgate\","
  "\"version\":\"1.0.0\","
  "\"limitation\":{"
    "\"max_message_length\":65536,"
    "\"max_subscriptions\":8,"
    "\"max_filters\":4,"
    "\"max_limit\":500,"
    "\"max_subid_length\":64,"
    "\"max_event_tags\":100,"
    "\"max_content_length\":32768,"
    "\"min_pow_difficulty\":0,"
    "\"auth_required\":false,"
    "\"payment_required\":false"
  "},"
  "\"retention\":[{\"kinds\":[0,1,2,3,4,5,6,7],\"time\":1814400}],"
  "\"relay_countries\":[\"DE\"]"
"}";

esp_err_t relay_nip11_handler(httpd_req_t *req)
{
    char accept[64] = "";
    httpd_req_get_hdr_value_str(req, "Accept", accept, sizeof(accept));

    if (strstr(accept, "application/nostr+json")) {
        httpd_resp_set_type(req, "application/nostr+json");
    } else {
        httpd_resp_set_type(req, "application/json");
    }

    httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
    httpd_resp_set_hdr(req, "Access-Control-Allow-Headers", "Content-Type, Accept");
    httpd_resp_set_hdr(req, "Access-Control-Allow-Methods", "GET, OPTIONS");
    return httpd_resp_send(req, NIP11_JSON, strlen(NIP11_JSON));
}

esp_err_t relay_nip11_options_handler(httpd_req_t *req)
{
    httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
    httpd_resp_set_hdr(req, "Access-Control-Allow-Headers", "Content-Type, Accept");
    httpd_resp_set_hdr(req, "Access-Control-Allow-Methods", "GET, OPTIONS");
    httpd_resp_set_status(req, "204 No Content");
    return httpd_resp_send(req, NULL, 0);
}