Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Hono context to options callback #3

Merged
merged 2 commits into from
Feb 17, 2025
Merged

Expose Hono context to options callback #3

merged 2 commits into from
Feb 17, 2025

Conversation

NuroDev
Copy link
Member

@NuroDev NuroDev commented Feb 17, 2025

Currently you can use a callback function to create the options for this Hono middleware, the Hono request context is not exposed & shared such that you could, for example, access the Hono context environment variables to set the token property to something else.

With this PR that issue is now fixed along with some minor refactoring & the updating of any tests affected.

Example

import { Hono } from "hono";
import { ronin } from "@ronin/hono";

const app = new Hono();

app.use("*", ronin(
	(c) => ({
		token: c.env.YOUR_TOKEN_NAME,
	})
));

app.get("/", async (c) => {
  const posts = await c.var.ronin.get.posts();
  return c.json(posts);
});

@NuroDev NuroDev added the enhancement New feature or request label Feb 17, 2025
@NuroDev NuroDev self-assigned this Feb 17, 2025
@NuroDev NuroDev enabled auto-merge (squash) February 17, 2025 16:06
Copy link

Released an experimental package:

bun add @ronin/hono@options-callback-experimental-5

This package will be removed after the pull request has been merged.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/index.ts 100.00% <100.00%> (ø)

@NuroDev NuroDev merged commit 9249ced into main Feb 17, 2025
3 checks passed
@NuroDev NuroDev deleted the options-callback branch February 17, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants