npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@ranger-theme/adobe-edege

v0.9.0

Published

## πŸŽ‰ Introduce

Downloads

78

Readme

@ranger-theme/adobe-edege

πŸŽ‰ Introduce

Adobe Edege Delivery

πŸ“š Documentation

πŸ“¦ Install

$ npm install --save-dev @ranger-theme/adobe-edege
# or
$ yarn add --save-dev @ranger-theme/adobe-edege
# or
$ pnpm add --save-dev @ranger-theme/adobe-edege

πŸ”¨ Usage

/pages/api/edege/[[...url]].ts

import { createProxyMiddleware } from 'http-proxy-middleware'
import type { NextApiRequest, NextApiResponse } from 'next/types'

const handler = (request: NextApiRequest, response: NextApiResponse) => {
  const apiProxy: any = createProxyMiddleware({
    changeOrigin: true,
    secure: true,
    pathRewrite: {
      '^/api/edege': ''
    },
    router: async () => {
      return process.env.NEXT_PUBLIC_EDEGE_URL
    }
  })

  apiProxy(request, response, (result) => {
    if (result instanceof Error) {
      throw result
    }

    throw new Error(`Request '${request.url}' is not proxied! We should never reach here!`)
  })
}

export const config = {
  api: {
    externalResolver: true,
    bodyParser: false
  }
}

export default handler
import { fetchEdege, HeadElement, HtmlELement, ScriptElement } from '@ranger-theme/adobe-edege'
import type { NextPageContext } from 'next/types'

const url: string = 'https://main--aem-block-collection--adobe.hlx.live'
const host: string = process.env.NEXT_PUBLIC_HOST_URL

const Home = ({ html }: { html: string }) => {
  return (
    <div>
      <HeadElement host={host} html={html} url={url}  />
      <ScriptElement html={html} url={url} />
      <div>
        <HtmlELement html={html} url={url} />
      </div>
    </div>
  )
}

Home.getInitialProps = async ({ pathname }: NextPageContext) => {
  const html = await fetchEdege({
    api: `${process.env.NEXT_PUBLIC_HOST_URL}api/edege/${pathname}`,
    url
  })

  return {
    html
  }
}

export default Home
import { fetchEdege, EdegeElement } from '@ranger-theme/adobe-edege'
import type { NextPageContext } from 'next/types'

const url: string = 'https://main--aem-block-collection--adobe.hlx.live'
const host: string = process.env.NEXT_PUBLIC_HOST_URL

const Home = ({ html }: { html: string }) => {
  return (
    <div>
      <EdegeElement host={host} html={html} url={url} />
    </div>
  )
}

Home.getInitialProps = async ({ pathname }: NextPageContext) => {
  const html = await fetchEdege({
    api: `${process.env.NEXT_PUBLIC_HOST_URL}api/edege/${pathname}`,
    url
  })

  return {
    html
  }
}

export default Home

when next router change page, it will fetch new html from edege server

import { useEffect, useState } from 'react'
import { fetchEdege, HeadElement, HtmlELement, ScriptElement } from '@ranger-theme/adobe-edege'
import Router from 'next/router'

const Resolver = ({ edegeURL, html }: { edegeURL: string; html: string }) => {
  const [isRender, setIsRender] = useState<boolean>(true)

  useEffect(() => {
    const handleRouteStart = () => {
      setIsRender(false)
    }

    const handleRouteComplete = () => {
      setIsRender(true)
    }

    Router.events.on('routeChangeStart', handleRouteStart)
    Router.events.on('routeChangeComplete', handleRouteComplete)

    return () => {
      Router.events.off('routeChangeStart', handleRouteStart)
      Router.events.off('routeChangeComplete', handleRouteComplete)
    }
  }, [])

return (
  <>
    <HeadElement host={host} html={html} url={edegeURL} />
    <ScriptElement html={html} url={edegeURL} />
    <div>{isRender && <HtmlELement html={html} url={edegeURL} />}</div>
  </>
)

Resolver.getInitialProps = async ({ asPath }: NextPageContext) => {
  const match: string[] = (asPath || '').split('/').slice(1)
  const pathname: string = match.join('/')
  const url: any = match?.pop()
  const urlKey: string = url.split('.')?.shift() || ''
  const edegeURL: string = process.env.NEXT_PUBLIC_EDEGE_URL
  const extname = path.extname(pathname)

  if (extname) return { edegeURL, html: '', urlKey }

  const html = await fetchEdege({
    api: `${process.env.NEXT_PUBLIC_HOST_URL}api/edege/${pathname}`,
    url: edegeURL
  })

  return {
    edegeURL,
    html,
    urlKey
  }
}

export default Resolver