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

@exporio/edge-sdk-hono

v0.2.1

Published

Exporio Edge SDK middleware for Hono framework

Downloads

64

Readme


ℹ️ Exporio is currently in Private Beta.

✉️ For early access, please contact us at [email protected].

🌎 Visit our website for more information.


🔥 Introduction

The scheme below illustrates the request-response lifecycle, showing how Exporio Middleware interacts with a separate Exporio-hosted Worker, which provides instructions for each request.

Request flow

🚀 Quick Start

The Edge SDK requires setting up a Cloudflare Worker with the Hono web framework.

Prerequisite: You need to sign-up for a Cloudflare account, and add your domain to Cloudflare so that Cloudflare is able to resolve your domain.

1. Get started with Cloudflare Workers by following this guide.

2. Install the Exporio Edge SDK in your worker project:

npm install @exporio/edge-sdk-hono

3. Update your worker code (index.ts) as follows:

import { Hono } from 'hono'
import { exporioMiddleware } from '@exporio/edge-sdk-hono'

type Variables = { contentUrl: string }

const app = new Hono<{ Variables: Variables }>()

app.use(
    '*',
    exporioMiddleware({
        url: 'https://edge-api.exporio.cloud',
        apiKey: 'EXPORIO_API_KEY',
    })
)

app.all('*', async (c) => {
    // https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#passthroughonexception
    c.executionCtx.passThroughOnException()

    const contentUrl = c.get('contentUrl')
    const request = new Request(contentUrl, c.req)

    const response = await fetch(request)

    return new Response(response.body, response)
})

export default app

Key points to note:

  • Replace EXPORIO_API_KEY with your API Key from the Exporio UI (Website Settings > API Keys).
  • The Exporio middleware will set a new contentUrl to fetch from in the case of a Split URL test, otherwise, the current request URL will be returned. Retrieve it with c.get('contentUrl').
  • A new Response must always be returned at the end to allow the middleware to modify the response - return new Response(response.body, response).

4. Configure your wrangler.toml:

account_id = "..."  # Cloudflare account id
name = "..."

main = "./src/index.ts"
compatibility_date = "2022-11-22"

route = "https://your_domain.com/*"

5. Deploy your wroker:

wrangler publish

Minimal example source code.

🎉 Congratulations! You can now start running A/B tests and personalizations on your website!

⚠️ Important

Consider the following aspects of implementation that can affect your worker and website, although they are not directly related to Exporio Middleware.

Static routes

Be sure to disable static routes so the worker doesn't interfere with them. Create a new path without running services in the Workers Routes section of Cloudflare. More details can be found in this community topic.

📄 License

This project is licensed under the terms of the MIT license.