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 🙏

© 2026 – Pkg Stats / Ryan Hefner

miniframe-router

v1.3.0

Published

Simple router for Express.js, making routes and controllers easy to manage.

Readme

MiniframeJS/Router

Простое и мощное решение для маршрутизации в приложениях на Express.js, которое предоставляет чистый и интуитивно понятный способ организации маршрутов и контроллеров.

Возможности

  • Простой синтаксис определения маршрутов
  • Действия на основе контроллеров
  • Группировка маршрутов для улучшенной организации
  • Автоматическая загрузка контроллеров

Документация

Установка

npm install miniframe-router
yarn add miniframe-router
pnpm add miniframe-router

Использование

Базовые маршруты

routes/index.ts

import { root, get, post, getRouter } from "miniframe-router";

// Определение корневого маршрута
root("index#index");

// Определение GET и POST маршрутов
get("/users", "users#show");
post("/users", "users#update");

// Определение GET и POST маршрутов
get("/posts", "posts#show");
post("/posts", "posts#update");

export default getRouter;

Маршруты с Middleware

Вы можете добавлять middleware к любому маршруту:

import { authenticate } from "./middlewares/auth";
import { validateUser } from "./middlewares/validation";

// Один middleware
get("/users/:id", "users#show", {
  withMiddlewares: [authenticate],
});

// Несколько middleware в порядке выполнения
post("/users", "users#create", {
  withMiddlewares: [authenticate, validateUser],
});

// Middleware в сгруппированных маршрутах
scope("admin", () => {
  get("/users", "users#show", {
    withMiddlewares: [authenticate],
  });

  post("/users", "users#create", {
    withMiddlewares: [authenticate, validateUser],
  });
});

Группировка маршрутов с Middleware

Вы можете добавлять middleware как к отдельным маршрутам, так и ко всей группе маршрутов:

import { authenticate } from "./middlewares/auth";
import { validateUser } from "./middlewares/validation";
import { logRequest } from "./middlewares/logging";

// Применить middleware ко всем маршрутам в группе
scope(
  "admin",
  () => {
    // Эти маршруты будут требовать аутентификации
    get("/users", "users#index");
    post("/users", "users#create");

    // Этот маршрут будет требовать и аутентификации, и валидации
    post("/users/:id", "users#update", {
      withMiddlewares: [validateUser],
    });
  },
  {
    withMiddlewares: [authenticate],
  }
);

// Комбинирование нескольких middleware для группы
scope(
  "api",
  () => {
    get("/stats", "stats#index");
    get("/health", "health#check");
  },
  {
    withMiddlewares: [authenticate, logRequest],
  }
);

Middleware, указанные в опциях группы, будут применяться ко всем маршрутам внутри этой группы. При этом вы можете добавлять дополнительные middleware к конкретным маршрутам, которые будут выполняться после middleware группы.

Структура файлов приложения:

src
  index.ts

  routes/
      index.ts
  controllers/
      indexController.ts
      usersController.ts
      postsController.ts

index.ts

import cors from "cors";
import cookieParser from "cookie-parser";
import getRoutes from "./routes"; // <<< ОПРЕДЕЛЯЕМ МАРШРУТЫ

const app = express();

app.use(
  cors({
    origin: ["http://localhost:3000"],
    credentials: true,
  })
);

app.use(cookieParser());
app.use(express.json());
app.use(getRoutes()); // <<< ИСПОЛЬЗУЕМ МАРШРУТЫ

app.listen(4000, () => {
  console.log(`Сервер запущен на порту: 4000`);
});

Группировка маршрутов

Группируйте связанные маршруты под общим префиксом:

routes/index.ts

import {
  root,
  get,
  post,
  getRouter,
  routeScope as scope,
} from "miniframe-router/routes";

scope("admin", () => {
  get("/users", "users#show");
  post("/users", "users#update");

  get("/posts", "posts#show");
  post("/posts", "posts#update");
});

export default getRouter;

Это создаст маршруты:

  • GET /admin/users -> controllers/admin/usersController.ts (действие show)
  • POST /admin/users -> controllers/admin/usersController.ts (действие update)
  • GET /admin/posts -> controllers/admin/postsController.ts (действие show)
  • POST /admin/posts -> controllers/admin/postsController.ts (действие update)

Структура контроллеров

Контроллеры должны находиться в директории controllers. Для маршрутов с префиксами контроллеры автоматически ищутся в соответствующих поддиректориях.

src
  index.ts

  routes/
      index.ts
  controllers/
      indexController.ts
      usersController.ts
      postsController.ts

      admin/
          usersController.ts
          postsController.ts

Пример контроллера:

controllers/usersController.ts

import { Request, Response } from "express";

export const show = (req: Request, res: Response) => {
  res.send("Список пользователей");
};

export const update = (req: Request, res: Response) => {
  res.send("Пользователь обновлен");
};

Справочник по API

  • root(controllerAction): Определяет корневой маршрут (/)
  • get(path, controllerAction): Определяет GET маршрут
  • post(path, controllerAction): Определяет POST маршрут
  • routeScope(prefix, callback): Группирует маршруты под общим префиксом

License

MIT.

Author

Ilya N. Zykin | the-teacher