@abcnews/mostess 中文文档教程

发布于 3年前 浏览 39 更新于 3年前

Mostess

女主人。

一个快速的'n dirty HTTP 服务器,提供可配置的开发和开发组合。 生产资源。 使用它在浏览时交换本地资源 生产站点,或将资源重定向到本地开发服务器。

Usage

它在端口 80 上运行,因此需要以 root 身份运行。 要设置:

  1. sudo node ./index.js -c <config.js>
  2. Change your /etc/hosts file to point the remote server to localhost

主机文件应如下所示:

0.0.0.0    www.example.org

服务器将继续运行,直到您手动将其终止。

Config

Config 作为 Javascript 模块进行管理。 支持以下值:

  • paths: An array containing local paths to search in. A local path is an array with two values: the requested path as a regex, and the local path it maps to. Eg. ["/", "/home/me/www/"]
  • searchandreplace: An object containing values to search and replace in the url. Eg. {"v1.0.0": "v1.0.1"}
  • ssl: An optional object containing the following: ** key: a path to a SSL key ** cert: a path to the SSL cert. ** passphrase: a string to unlock the private key (optional);

配置示例如下:

module.exports = {
  searchandreplace: [
    // Point the remote foo to the local bar
    ['foo.js', 'bar.js'],
  ],
  redirect: [
    // Redirect assets to another server
    // foo.css or bar.css will be redirected to the server on localhost:8000
    [ /.*((foo|bar).css)$/, 'http://localhost:8000/$1' ],
  ],
  paths: [
    // Redirect this path to the local build folder
    [
      /^\/remote\/path\/v1.0.0/,
      'build/',
    ],
    // Use regexes to redirect multiple remotes to the local path
    [
      /^\/remote\/path\/[^/]+/,
      'build/',
    ],
  ],
  ssl: {
      key: "path/to/key",
      cert: "path/to/cert",
      passphrase: "my passphrase (optional)"
  }
};

SSL

如果您正在测试使用 SSL 的站点,则 SSL 很有用。 端口 443 上的 SSL 已启用 通过命令行上的 SSL 选项,或通过在 配置文件。

例如。

node index.js --key='serv.key' --cert='server.cert'

生成您自己的 SSL 证书:

openssl req  -nodes -new -x509  -keyout server.key -out server.cert

Some warnings

这是一个开发服务器。 它不打算在开放的互联网上运行 或者没有安装防火墙。 采取适当的预防措施。

Mostess

The hostess.

A quick 'n dirty HTTP server that serves up a configurable mix of dev & production resources. Use this to swap in local resources while browsing a production site, or redirect resources to a local dev server.

Usage

This runs on port 80 and thus needs to be run as root. To set up:

  1. sudo node ./index.js -c <config.js>
  2. Change your /etc/hosts file to point the remote server to localhost

The hosts file should look as follows:

0.0.0.0    www.example.org

The server will continue to run until you kill it manually.

Config

Config is managed as a Javascript module. The following values are supported:

  • paths: An array containing local paths to search in. A local path is an array with two values: the requested path as a regex, and the local path it maps to. Eg. ["/", "/home/me/www/"]
  • searchandreplace: An object containing values to search and replace in the url. Eg. {"v1.0.0": "v1.0.1"}
  • ssl: An optional object containing the following: ** key: a path to a SSL key ** cert: a path to the SSL cert. ** passphrase: a string to unlock the private key (optional);

An example config follows:

module.exports = {
  searchandreplace: [
    // Point the remote foo to the local bar
    ['foo.js', 'bar.js'],
  ],
  redirect: [
    // Redirect assets to another server
    // foo.css or bar.css will be redirected to the server on localhost:8000
    [ /.*((foo|bar).css)$/, 'http://localhost:8000/$1' ],
  ],
  paths: [
    // Redirect this path to the local build folder
    [
      /^\/remote\/path\/v1.0.0/,
      'build/',
    ],
    // Use regexes to redirect multiple remotes to the local path
    [
      /^\/remote\/path\/[^/]+/,
      'build/',
    ],
  ],
  ssl: {
      key: "path/to/key",
      cert: "path/to/cert",
      passphrase: "my passphrase (optional)"
  }
};

SSL

SSL is useful if you're testing a site that uses SSL. SSL on port 443 is enabled through the SSL options on the command line, or by specifying SSL options in the config file.

Eg.

node index.js --key='serv.key' --cert='server.cert'

To generate your own SSL certificate:

openssl req  -nodes -new -x509  -keyout server.key -out server.cert

Some warnings

This is a development server. It is not intended to be run on the open Internet or without a firewall in place. Take appropriate precautions.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文