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

easy-router

v2.3.1

Published

npm install easy-router

Downloads

24

Readme

easy-router

NPM version Downloads Build Status Coverage Status

简易路由,可以快速创建http文件服务,用于测试本地项目

模块是自己写来用于快速方便创建文件服务, 或者http服务的, 不依赖任何外部模块, 写着练手, 自己觉得挺方便好用的~

Install

npm install easy-router

npm install easy-router -g

Usage

快速使用

var Router = require("easy-router");
Router().setMap('**/**' , '**/*').listen(3030)

接入server

var Router = require("easy-router");
var maps = {
  "/topic/*":"./pratice/topic_*.html",        // 页面访问
  "*, *_360, *_baidu":"html/Topic/*.html",    // 可以用逗号相隔
  "/public/**/*":"./public/biz009/**/*",      // 静态资源
  "/runMethod":function(req , res){           // 可以加方法
    res.end("test")
  }
}
var router = Router({
    root: __dirname,    // 项目根目录
    maps: maps,         // 初始的路由表
    useZlib: true,      // 使用gzip压缩
    useCache: true,     // 使用http缓存, 默认为false
    maxCacheSize: 1     // 凡是小于maxCacheSize的资源将以文件内容的md5值作为Etag,单位为MB
});

http.createServer(function(req , res){
    router.route(req , res);
}).listen(3030);

命令行启动

需全局安装easy-router

在想创建文件服务的目录下执行router并按回车,默认端口为33750,如果当前端口被占用,则会自动分配一个可用端口 image

如果输入命令时添加端口号:router -p 9030,则会使用命令里的端口 image

服务启动后,访问:http://localhost:33750/ 即可看到网站根目录的文件列表 如果输入filename为/:keyword,则会列出文件名内含keyword字符的文件/文件夹,如果keyword为空则会列出全部文件/文件夹 image

命令行参数:

router -h --help            help
router -v --version         show version
router -p --port <port>     set server port

Rules

**代表匹配多级目录, *代表匹配字符

1.当规则如下时, 则当我访问/topic/test的时候, 将会解析成访问./pratice/topic_test.html

{"/topic/*": "./pratice/topic_*.html"}

2.当规则如下时, 当我访问/public/javascript/app/index.js, 将会解析成访问./dist/public/javascript/app/index.js

{"/public/**/*": "./dist/public/**/*"}

3.当规则如下时, 则可以按照文件路径访问项目目录下所有文件

{"**/*", "**/*"}

API

Router(options)

实例化一个router对象

router.listen(port);

监听端口,执行该方法会自动创建http server, 该方法返回http server对象

router.setMap(maps);

添加路由映射,该方法返回router对象

root

项目根目录, 默认为./

maps

路由表, 可以在初始化时传入相应路由表

useCache

默认值为false,是否使用简易http缓存

useZlib

默认值为true,是否开启gzip压缩

Test

make test

或者

make cover

Author

whxaxes

License

MIT.