Skip to content
LogoLogo

Mppx.toNodeListener

Adapt payments for Node.js HTTP

Wraps a payment handler to create a Node.js HTTP listener.

Usage

import * as  from 'node:http'
import { ,  } from 'mppx/server'
 
const  = .({
  : [.()],
})
 
.(async (, ) => {
  const  = await .(
    .({
      : '0.1', 
      : '0x...', 
      : '0x...',
    }),
  )(, )
 
  if (. === 402) return
 
  .('OK')
})

Behavior

  • On 402: Writes the Challenge response headers and body, then ends the connection.
  • On 200: Sets the Payment-Receipt header; the caller writes the response body.

Return type

type ReturnType = (
  req: IncomingMessage,
  res: ServerResponse,
) => Promise<MethodFn.Response<Transport.Http>>

Parameters

handler

  • Type: (input: Request) => Promise<MethodFn.Response<Transport.Http>>

The payment handler function returned by calling an intent on the payment object.

import * as  from 'node:http'
import { ,  } from 'mppx/server'
 
const  = .({
  : [.()],
})
 
.(async (, ) => {
  const  = await .(
    .({
      : '0.1',
      : '0x...',
      : '0x...',
    }),
  )(, )
 
  if (. === 402) return
  .('OK')
})