Skip to content

Generate electron protocol handlers from lazy-loaded fetch API handlers

License

Notifications You must be signed in to change notification settings

AgregoreWeb/fetch-to-electron-protocol-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch-to-electron-protocol-handler

Generate electron protocol handlers from lazy-loaded fetch API handlers

Refactored from the Agregore Browser

Usage

const fetchToHandler = require('fetch-to-electron-protocol-handler')
const {protocols, session} = require('electron')

const {handler} = fetchToHandler(getFetch, session.defaultSession)

protcols.registerStreamProtocol('example', handler)

async function getFetch() {
 // Asynchronously initialize your `fetch()` function
 // This is where you can set up your p2p nodes
 // Note that the initializing will happen on the initial invocation
 return async function fetch({url, ...opts}) => {
   const convertedURL = new URL(url)
   url.protocol = 'https:'

   return globalThis.fetch(convertedURL.href, opts)
 }
}

About

Generate electron protocol handlers from lazy-loaded fetch API handlers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published