Skip to content

Instantly share code, notes, and snippets.

@lvnilesh
Last active April 16, 2024 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvnilesh/d65b609754d9a6c5541e4e6e355bbe9f to your computer and use it in GitHub Desktop.
Save lvnilesh/d65b609754d9a6c5541e4e6e355bbe9f to your computer and use it in GitHub Desktop.
easy-nip5 on cloudflare

STEP 1: Create a worker and map it to a route like below.

*yourdomain.com/.well-known/nostr.json*

STEP 2: Use this sample as your worker.js

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

const nostrjson = `{
  "names": {
    "YOUR_NOSTR_NAME": "YOUR_NOSTR_PUBLIC_KEY_IN_HEX"
  }
}
`;

async function handleRequest(request) {
  return new Response(
    nostrjson,
    {
      status: 200,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
        'Accept-Ranges': 'bytes',
        'Content-Security-Policy': "connect-src 'self' ws: wss: * ;"
      }
    }
  )
}

STEP 3: You are done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment