Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 777255 of test/httpd

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/test_httpd
  • Revision title: test/httpd
  • Revision id: 777255
  • Created:
  • Creator: evold
  • Is current revision? No
  • Comment link to fx 36 changes and to addon-httpd npm module

Revision Content

This module was removed in Firefox 36, please use the addon-httpd npm module instead.

An HTTP server for the Mozilla platform, which can be used in unit tests.

Usage

The most basic usage is:

var { startServerAsync } = require("sdk/test/httpd");
var srv = startServerAsync(port, basePath);
require("sdk/system/unload").when(function cleanup() {
  srv.stop(function() { // you should continue execution from this point.
  })
});

This starts a server in background (assuming you're running this code in an application that has an event loop, such as Firefox). The server listens at https://localhost:port/ and serves files from the specified directory. You can serve static content or use SJS scripts, as described in documentation on developer.mozilla.org.

You can also use nsHttpServer to start the server manually:

var { nsHttpServer } = require("sdk/test/httpd");
var srv = new nsHttpServer();
// further documentation on developer.mozilla.org

See HTTP server for unit tests for general information.

Revision Source

<div class="warning">
<p>This module was removed in <a href="/en-US/Firefox/Releases/36">Firefox 36</a>, please use the <a href="https://www.npmjs.com/package/addon-httpd">addon-httpd</a> npm module instead.</p>
</div>

<p><span class="seoSummary">An HTTP server for the Mozilla platform, which can be used in unit tests.</span></p>

<h2 id="Usage">Usage</h2>

<p>The most basic usage is:</p>

<pre class="brush: js">
var { startServerAsync } = require("sdk/test/httpd");
var srv = startServerAsync(port, basePath);
require("sdk/system/unload").when(function cleanup() {
  srv.stop(function() { // you should continue execution from this point.
  })
});</pre>

<p>This starts a server in background (assuming you're running this code in an application that has an event loop, such as Firefox). The server listens at <code>https://localhost:port/</code> and serves files from the specified directory. You can serve static content or use <a href="https://developer.mozilla.org/en/HTTP_server_for_unit_tests#SJS:_server-side_scripts">SJS scripts</a>, as described in documentation on developer.mozilla.org.</p>

<p>You can also use <code>nsHttpServer</code> to start the server manually:</p>

<pre class="brush: js">
var { nsHttpServer } = require("sdk/test/httpd");
var srv = new nsHttpServer();
// further documentation on developer.mozilla.org</pre>

<p>See <a href="https://developer.mozilla.org/En/HTTP_server_for_unit_tests">HTTP server for unit tests</a> for general information.</p>
Revert to this revision