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 509053 of test/httpd

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/test_httpd
  • Revision title: test/httpd
  • Revision id: 509053
  • Created:
  • Creator: wbamberg
  • Is current revision? No
  • Comment

Revision Content

Experimental

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="note">
 <p>Experimental</p>
</div>
<p><span class="seoSummary">An HTTP server for the Mozilla platform, which can be used in unit tests.</span></p>
<h2>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