(request: Request, response: Response, next: NextFunction)
| 40 | } |
| 41 | |
| 42 | export 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, |
no test coverage detected