
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
hono-router
Advanced tools
hono-router
is a script that generates a file-based router for Hono, a small, simple, and ultrafast web framework for the Edges. It automatically creates routes based on your file structure and exports, making it easier to organize and maintain your Hono application.
[id].ts
becomes :id
in the route)[[blob]].ts
for one or more segments, [...rest].ts
for zero or more)npm install hono-router
src/
routes/
index.ts
users/
index.ts
[id].ts
UserList.tsx
posts/
index.ts
[id].ts
PostEditor.tsx
docs/
[...slug].ts # Catch-all route (zero or more segments)
api/
[[...path]].ts # Greedy route (one or more segments)
src/routes/users/[id].ts
:import { Context } from 'hono';
export const onRequestGet = (c: Context) => {
const id = c.req.param('id');
return c.json({ message: `Get user ${id}` });
};
export const onRequestPut = (c: Context) => {
const id = c.req.param('id');
return c.json({ message: `Update user ${id}` });
};
bunx hono-router src/routes router.ts [options]
or
npx hono-router src/routes router.ts [options]
Options:
--watch
or -w
: Enable watch mode to automatically regenerate routes on file changes--deno
: Generate Deno-compatible importsThis will generate a router.ts
file with all your routes.
import { Hono } from 'hono';
import { loadRoutes } from './router';
const app = new Hono();
loadRoutes(app);
export default app;
hono-router
allows you to co-locate component files with your routes. Any TypeScript or TypeScript JSX (.tsx
) files that start with a capital letter are ignored by the router generation process. This enables you to keep your components close to the routes that use them without affecting the routing logic.
For example:
src/routes/users/UserList.tsx
will be ignored by the routersrc/routes/users/index.ts
will be processed for route generationThis feature helps in maintaining a clean and organized project structure where components and their associated routes are kept together.
To enable watch mode, use the --watch
or -w
flag when running the script:
npx hono-router src/routes router.ts --watch
In watch mode, the script will continuously monitor your routes directory and automatically regenerate the router file when changes are detected.
The generator supports the following HTTP methods:
To use these methods, export functions with the corresponding names in your route files:
onRequestGet
onRequestPut
onRequestPost
onRequestDelete
onRequestPatch
Standard dynamic routes match a single path segment:
[id].ts
→ Route: :id
/users/[id].ts
matches /users/123
but not /users/123/posts
Greedy routes can match multiple path segments:
[[param]]
(one or more segments)[[path]].ts
→ Route: :path{.+}
/api/[[path]].ts
matches /api/v1
, /api/v1/users
, etc./api
(requires at least one segment)[...param]
(zero or more segments)[...slug].ts
→ Route: :slug{.*}
/docs/[...slug].ts
matches /docs
, /docs/intro
, /docs/guides/setup
, etc.Routes are automatically sorted to ensure correct matching:
/api/users
) - highest priority/api/:id
) - medium priority/api/:path{.+}
) - lowest priorityThis ensures that more specific routes are always matched before catch-all routes.
// routes/proxy/[[...path]].ts
export const onRequestGet = async (c: Context) => {
const path = c.req.param('path');
// Forward request to backend API
return fetch(`https://backend.api/${path}`);
};
// routes/docs/[...slug].ts
export const onRequestGet = (c: Context) => {
const slug = c.req.param('slug') || 'index';
// Serve documentation page based on slug
return c.html(renderDocsPage(slug));
};
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the ISC License.
FAQs
hotloading script to generate file-based routing config for Hono
The npm package hono-router receives a total of 203 weekly downloads. As such, hono-router popularity was classified as not popular.
We found that hono-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.