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

server-static

v2.0.5

Published

a static file server

Downloads

461

Readme

static-server

静态文件服务器,支持SPA,类似于live-server,支持自定义ajax请求路径mock数据,支持模拟ajax跨域请求进行接口调试

安装

npm install server-static -g

安装完成

可通过

static-server --help 或者 static-server -h

命令查看配置帮助文档

可通过

static-server --port=3001 或者 static-server -p=3001

通过指定监听端口

可通过

static-server --slient 或者 static-server -s

指定不监听文件

可通过

static-server --dir=xxxxx 或者 static-server -d=xxxx

指定在哪个目录下启动服务

也可以通过

static-server

的方式(读取默认配置)启动本服务

配置(如不指定,就用默认配置)

可以通过在项目根目录下新建名为static-server.config.js的文件进行配置

//  static-server.config.js

module.exports = {
	port: 4000,                         // 监听端口,默认3000,当端口被占用时随机
	entry: "index.html",                // 首页文件,及当路径为"/"时响应的页面 
    target: "http://localhost:8080",    // 调试ajax接口的真实地址和前缀
  	slient: true,				      //  是否监听文件
	ignores: [                          //  忽略过滤器(可传入单个函数或者由函数组成的数组)
		function(file) {
		    return /node_modules/.test(file);
		}
	],
	routers: [                          //  自定义请求路由
	    {
	        url: "/login",              //  请求的真实地址
	        method: "GET",
	        cross: true                 //  是否跨域请求
	    },
		{
			url: "/main",                       //  路由
			method: "GET",                      //  请求方式
			handler: function(req, res, next) { //  改路由的处理函数(与connect模块调用方法一致)
				console.log("请求进来了");
				res.statusCode = 200;
				res.end(JSON.stringify({
					res: "test main"
				}));
			}
		},
		{
			url: "/main2",
			method: "POST",
			handler: function(req, res, next) {
				console.log(req.body);
				res.statusCode = 200;
				res.end(JSON.stringify({
					tip: "请求内容",
					res: req.body
				}));
			}
		}
	]
};

在所有接口都需要跨域请求时,可以将static-server.config.js中的routers指定成一个对象,为如下结构即可支持全部跨域调试,更加方便调试

//  static-server.config.js
module.exports = {
	//	...
    routers: {
        url: "*",
        method: "*",
        cross: true
    }
	//	...
};