1.1.9 • Published 5 months ago

@sunshj/express-routes-mount v1.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

@sunshj/express-routes-mount

用于自动挂载 Express.js 路由器,从指定目录加载路由模块,并将其挂载到提供的 Express.js 应用程序实例上。

安装

npm i @sunshj/express-routes-mount

使用方法

ES modules

import express from 'express'
import mount from '@sunshj/express-routes-mount'
import path from 'path'
import createError from 'http-errors'

const app = express()

mount(app, {
  path: path.join(__dirname, './routes'),
  logger: true,
  prefix: '/private',
})

app.use((req, res, next) => {
  next(createError(404))
})

app.listen(3000)

CommonJS

const express = require('express')
const { autoMount } = require('@sunshj/express-routes-mount')
const path = require('path')
const createError = require('http-errors')

const app = express()

autoMount(app, {
  path: path.join(__dirname, './routes'),
  logger: true,
  prefix: '/private',
})

app.use((req, res, next) => {
  next(createError(404))
})

app.listen(3000)

类型声明

type RouteTableRow = Record<string, string>;
interface Options {
    path?: string;
    logger?: boolean | ((data: RouteTableRow[]) => void) | {
        enable: boolean;
        baseUrl?: string;
    };
    prefix?: string;
    entryFileName?: string;
}

declare function autoMount(app: Express, options?: Options): void;
1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago