3w 中文文档教程

发布于 10年前 浏览 25 项目主页 更新于 3年前

3w

用于静态文件传送的简单快速服务器。 在设置一个简单的 Http 服务器来公开特定目录时,我们有很多选择。 一种有一定限制的常用方法是使用 python,例如:

python -m SimpleHTTPServer 8080

它允许我将当前目录公开为特定端口号上的 http 服务器。 我创建了 3w 作为具有大量高级功能的替代方案。 能够设置 http 代理是一项有用的功能,可以在开发 Web 应用程序时省去很多麻烦。 当前版本中未提供 Http 代理,但它们很快就会以一种很好且有用的方式来设置配置。

Installation

3w 现在在 npm 上,要安装它,您只需在终端

npm install 3w

运行它:

node node_modules/3w/3w.js src --3000

上 启用 https 你也可以传递 --https 这通常需要你在机器上有 sudo 访问权限:

sudo node node_modules/3w/3w.js src --3000 --https

API

你也可以 require 3w 作为一个模块,并像这样设置服务器:

var www = require('3w'),
  app;

app = www({
  enableHTTPS: true,
  port: 8888,
  dir: 'src'
});

or:

//This will expose the 'app' folder and 'enableHTTPS' will be false
app = www({
  port: 8888
});

or:

//This will expose the 'src' folder on '9000' and 'enableHTTPS' will be false
app = www({
  dir: 'src'
});

or:

//This will expose the 'app' folder on '9000' and 'enableHTTPS' will be false
app = www();

使用 3w 你也可以调整 app 对象来设置你的 http-proxies 喜欢:

var www = require('3w'),
  app;

function proxy(app){
  //...
}

app = www({
  enableHTTPS: true,
  port: 8888,
  dir: 'src',
  proxy: proxy
});

3w

Simple express server for static file delivering. When it comes to setting up a simple Http server to expose a specific dir, we have bunch of options. One of the usual way of doing that which has a tone of restrictions, is using python like:

python -m SimpleHTTPServer 8080

which allows me to expose the current dir as a http server on the specific port number. I created 3w as an alternative with bunch of advanced features. Being able to set up http proxies is one of the useful features which saves a lot of pain when developing a web application. Http proxies are not provided in the current version but they will be soon with a nice and useful way of setting up the configuration.

Installation

3w is now on npm, to install it all you need is to run this on terminal:

npm install 3w

Now to run a server and expose a directory (let's say its name is src) all you should do is:

node node_modules/3w/3w.js src --3000

To enable https you could also pass --https which usually needs you to have sudo access on the machine:

sudo node node_modules/3w/3w.js src --3000 --https

API

You could also require 3w as a module, and set up the server like:

var www = require('3w'),
  app;

app = www({
  enableHTTPS: true,
  port: 8888,
  dir: 'src'
});

or:

//This will expose the 'app' folder and 'enableHTTPS' will be false
app = www({
  port: 8888
});

or:

//This will expose the 'src' folder on '9000' and 'enableHTTPS' will be false
app = www({
  dir: 'src'
});

or:

//This will expose the 'app' folder on '9000' and 'enableHTTPS' will be false
app = www();

Using 3w you could also tweak the app object to set up your http-proxies like:

var www = require('3w'),
  app;

function proxy(app){
  //...
}

app = www({
  enableHTTPS: true,
  port: 8888,
  dir: 'src',
  proxy: proxy
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文