MCPcopy Create free account
hub / github.com/cameri/nostream / rootRequestHandler

Function rootRequestHandler

src/handlers/request-handlers/root-request-handler.ts:42–157  ·  view source on GitHub ↗
(request: Request, response: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

40}
41
42export const rootRequestHandler = (request: Request, response: Response, next: NextFunction) => {
43 const settings = createSettings()
44 const pathPrefix = getPublicPathPrefix(request, settings)
45
46 if (hasExplicitNostrJsonAcceptHeader(request)) {
47 const {
48 info: { name, description, banner, icon, pubkey: rawPubkey, self: rawSelf, contact, relay_url, terms_of_service },
49 } = settings
50
51 const paymentsUrl = new URL(relay_url)
52 paymentsUrl.protocol = paymentsUrl.protocol === 'wss:' ? 'https:' : 'http:'
53 paymentsUrl.pathname = joinPathPrefix(pathPrefix, '/invoices')
54
55 const content = settings.limits?.event?.content
56 const eventLimits = settings.limits?.event
57 const createdAtLimits = eventLimits?.createdAt
58 const hasAdmissionRestriction =
59 settings.payments?.enabled === true &&
60 Boolean(settings.payments?.feeSchedules?.admission?.some((feeSchedule) => feeSchedule.enabled))
61 const hasWriteRestriction =
62 hasAdmissionRestriction ||
63 (eventLimits?.eventId?.minLeadingZeroBits ?? 0) > 0 ||
64 (eventLimits?.pubkey?.minLeadingZeroBits ?? 0) > 0 ||
65 (eventLimits?.pubkey?.whitelist?.length ?? 0) > 0 ||
66 (eventLimits?.pubkey?.blacklist?.length ?? 0) > 0 ||
67 (eventLimits?.kind?.whitelist?.length ?? 0) > 0 ||
68 (eventLimits?.kind?.blacklist?.length ?? 0) > 0
69
70 const pubkey = rawPubkey.startsWith('npub1') ? fromBech32(rawPubkey) : rawPubkey
71 const self = rawSelf?.startsWith('npub1') ? fromBech32(rawSelf) : rawSelf
72
73 const relayInformationDocument = {
74 name,
75 description,
76 ...(banner !== undefined ? { banner } : {}),
77 ...(icon !== undefined ? { icon } : {}),
78 pubkey,
79 ...(self !== undefined ? { self } : {}),
80 contact,
81 supported_nips: packageJson.supportedNips,
82 supported_nip_extensions: packageJson.supportedNipExtensions,
83 supported_mips: packageJson.supportedMips,
84 software: packageJson.repository.url,
85 version: packageJson.version,
86 ...(terms_of_service !== undefined ? { terms_of_service } : {}),
87 limitation: {
88 max_message_length: settings.network.maxPayloadSize,
89 max_subscriptions: settings.limits?.client?.subscription?.maxSubscriptions,
90 max_filters: settings.limits?.client?.subscription?.maxFilters,
91 max_limit: settings.limits?.client?.subscription?.maxLimit,
92 max_subid_length: settings.limits?.client?.subscription?.maxSubscriptionIdLength,
93 min_prefix: settings.limits?.client?.subscription?.minPrefixLength,
94 max_event_tags: 2500,
95 max_content_length: Array.isArray(content)
96 ? content[0].maxLength // best guess since we have per-kind limits
97 : content?.maxLength,
98 min_pow_difficulty: eventLimits?.eventId?.minLeadingZeroBits,
99 auth_required: false,

Callers 2

index.tsFile · 0.90

Calls 8

createSettingsFunction · 0.90
getPublicPathPrefixFunction · 0.90
joinPathPrefixFunction · 0.90
fromBech32Function · 0.90
getTemplateFunction · 0.90
escapeHtmlFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected