Web Server For Firefox
Live Server Web Extension – Firefox Add-ons
Live Server – Web Extension is a browser extension that helps you to live reload feature for dynamic content (PHP,, ASPNET — Whatever, it doesn’t matter) extension is for Live Server (VSCode Extension – required v3. 0. 0+) have to install VSCode & Live Server extension for Vscode in order to use this Add: GifFollow this link to setup: are you enjoying Live Server Web Extension? If you think this add-on violates Mozilla’s add-on policies or has security or privacy issues, please report these issues to Mozilla using this don’t use this form to report bugs or request add-on features; this report will be sent to Mozilla and not to the add-on add-on needs to:Access browser tabsAccess your data for all websitesBug Fixed (- reloading all tabs)
Embedding an HTTP Web Server in Firefox OS – Mozilla Hacks
Nearing the end of last year, Mozilla employees were gathered together for a week of collaboration and planning. During that week, a group was formed to envision what the future of Firefox OS might be surrounding a more P2P-focused Web. In particular, we’ve been looking at harnessing technologies to collectively enable offline P2P connections such as Bluetooth, NFC and WiFi Direct.
Since these technologies only provide a means to communicate between devices, it became immediately clear that we would also need a protocol for apps to send and receive data. I quickly realized that we already have a standard protocol for transmitting data in web apps that we could leverage – HTTP.
By utilizing HTTP, we would already have everything we’d need for apps to send and receive data on the client side, but we would still need a web server running in the browser to enable offline P2P communications. While this type of HTTP server functionality might be best suited as part of a standardized WebAPI to be baked into Gecko, we actually already have everything we need in Firefox OS to implement this in JavaScript today!
zTCPSocket
Packaged apps have access to both raw TCP and UDP network sockets, but since we’re dealing with HTTP, we only need to work with TCP sockets. Access to the TCPSocket API is exposed through zTCPSocket which is currently only exposed to “privileged” packaged apps with the tcp-socket permission:
“type”: “privileged”,
“permissions”: {
“tcp-socket”: {}},
In order to respond to incoming HTTP requests, we need to create a new TCPSocket that listens on a known port such as 8080:
var socket = (8080);
When an incoming HTTP request is received, the TCPSocket needs to handle the request through the onconnect handler. The onconnect handler will receive a TCPSocket object used to service the request. The TCPSocket you receive will then call its own ondata handler each time additional HTTP request data is received:
socket. onconnect = function(connection) {
= function(evt) {
();};};
Typically, an HTTP request will result in a single calling of the ondata handler. However, in cases where the HTTP request payload is very large, such as for file uploads, the ondata handler will be triggered each time the buffer is filled, until the entire request payload is delivered.
In order to respond to the HTTP request, we must send data to the TCPSocket we received from the onconnect handler:
var response = ‘HTTP/1. 1 200 OK\r\n’;
var body = ‘Hello World! ‘;
response += ‘Content-Length: ‘ + + ‘\r\n’;
response += ‘\r\n’;
response += body;
(response);
();};
The above example sends a proper HTTP response with “Hello World! ” in the body. Valid HTTP responses must contain a status line which consists of the HTTP version HTTP/1. 1, the response code 200 and the response reason OK terminated by a CR+LF \r\n character sequence. Immediately following the status line are the HTTP headers, one per line, separated by a CR+LF character sequence. After the headers, an additional CR+LF character sequence is required to separate the headers from the body of the HTTP response.
FxOS Web Server
Now, it is likely that we will want to go beyond simple static “Hello World! ” responses to do things like parsing the URL path and extracting parameters from the HTTP request in order to respond with dynamic content. It just so happens that I’ve already implemented a basic-featured HTTP server library that you can include in your own Firefox OS apps!
FxOS Web Server can parse all parts of the HTTP request for various content types including application/x-www-form-urlencoded and multipart/form-data. It can also gracefully handle large HTTP requests for file uploads and can send large binary responses for serving up content such as images and videos. You can either download the source code for FxOS Web Server on GitHub to include in your projects manually or you can utilize Bower to fetch the latest version:
bower install justindarc/fxos-web-server –save
Once you have the source code downloaded, you’ll need to include dist/ in your app using a
WebDrive
Files