serve2 支持node.js的快速启动Web服务调试工具

程序名称:serve2

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

serve2 介绍

与 Python 的 SimpleHTTPServer,Node.js 的 serve 不同,serve2
一个支持动态文件的工具,前者们只支持静态文件,而serve2支持编写代码动态处理和返回http请求。

常常我们可能会有这样的需求场景:无论是在开发时还是尝试某个框架时,往往需要处理请求参数、Cookies、Http
headers等,这样简单的静态文件服务器便无法满足这种需求了。

于是serve2便应运而生了,基于Tj的serve开发,使用起来跟一般的静态文件服务器相同,执行一条命令即可。详细的用法介绍如下。

npm install -g serve2
λ serve2 --help


  Usage: serve2 [options] [dir]


  Options:


    -h, --help                output usage @R_389_4045@ion
    -V, --version             output the version number
    -a, --auth <user>:<pass>  specify basic auth credentials
    -F, --format <fmt>        specify the log format string
    -p, --port <port>         specify the port [3000]
    -H, --hidden              enable hidden file serving
    -S, --no-stylus           disable stylus rendering
    -J, --no-jade             disable jade rendering
        --no-less             disable less css rendering
    -I, --no-icons            disable icons
    -L, --no-logs             disable request logging
    -D, --no-dirs             disable directory serving
    -f, --favicon <path>      serve the given favicon
    -M, --mocks <path>        mock files directory
        --cookies             add cookies parse support
    -C, --cors                allows cross origin access serving
        --compress            gzip or deflate the response
        --exec <cmd>          execute command on each request

准备一个文件夹,如mock,然后启动的时候用-M参数指定。此目录下即为动态文件目录,可以模拟后端请求处理。如:

// mock/test.js  module.exports = function(req, res, next) { 
  var query = req.query; 
  var reqBody = req.body; 
  // ... res.end(query.hi);
}

则请求:

都将返回hello。js文件中的函数即是connect的中间件函数形式。

另外,也可以是json或其它文本文件, 甚至可以是目录:

当某个HTTP请求我们希望转发给服务器来处理时,可以在工作目录下创建一个文件名为proxylist.json,内容格式如下:

{
  "/": "http://www.baidu.com",
  "/t/180521": "https://www.v2ex.com" 
}

启动serve2后访问http://localhost:3000/,请求即会被proxy到baidu.com

serve2 官网

https://github.com/ijse/serve2

相关编程语言

MuPlayer 是一款跨平台、轻量级的音频播放解决方案,...
OS FLV 是一个 开源和可嵌入网页的flv播放器。 这个...
DewPlayer音乐播放器,样式很简单,而且很实用.播放器...
JW FLV MEDIA PLAYER是一个开源的在网页上使用的Fla...
Speakker 是一个基于 Web 浏览器的音乐播放器,只提...
Player Framework 是一个开源的支持 HTML5 的视频播...