An HTTP Web Server for Chrome (chrome.sockets API)
JavaScript HTML Other
Switch branches/tags
Nothing to show
Clone or download
kzahel Merge pull request #149 from stardustapp/master
Improve POST bodies support
Latest commit f7bdc4c Jul 9, 2018
Permalink
Failed to load latest commit information.
images add credits file Feb 8, 2016
polymer-ui add modrewrite advanced option, and add tooltips Feb 17, 2017
test websocket working May 5, 2016
CREDITS add credits file Feb 8, 2016
LICENSE Create LICENSE Apr 24, 2014
README.md Update README.md Aug 18, 2016
TODO update todo May 11, 2016
background.js fix race condition May 7, 2016
buffer.js websocket working May 5, 2016
buy.js update package and UI a little Sep 5, 2014
chromesocketxhr.js fixup logging Apr 29, 2016
common.js Automatic folder creation during file upload Jan 21, 2018
connection.js Support zero-length POST bodies Jul 4, 2018
directory-listing-template.html Update directory-listing-template.html Apr 8, 2018
encoding.js Use UTF-8 encoding when converting in stringToUint8Array() and arrayB… Mar 1, 2015
handlers.js Automatic folder creation during file upload Jan 21, 2018
hidden.html properly support background operation over all interfaces on chromeos Mar 6, 2016
hidden.js properly support background operation over all interfaces on chromeos Mar 6, 2016
httplib.js add semicolon to end of files for minimize Mar 1, 2016
index.html Update index.html Sep 29, 2015
index.js polymer bower build file Oct 1, 2015
log-full.js update 0.4.1 add logging option May 23, 2016
manifest.json fix CORS headers OPTIONS preflight for PUT Sep 22, 2017
manifest.json.scratch add link Feb 20, 2014
mime.js new idle option, stops web server if idle Apr 6, 2016
minimize.sh Simplify minimize.sh script May 2, 2018
package.sh update 0.4.1 add logging option May 23, 2016
request.js add _DEBUG flag for less logging Mar 1, 2016
stream.js update UI with more options May 7, 2016
test.html stream large files (content range headers) Feb 21, 2014
underscore.js workin' Feb 19, 2014
upnp.js fix CORS headers OPTIONS preflight for PUT Sep 22, 2017
webapp.js Automatic folder creation during file upload Jan 21, 2018
websocket.js set_nodelay option May 6, 2016

README.md

Try it now in CWS

Chrome Web Server - an HTTP web server for Chrome (chrome.sockets)

Get it in the chrome web store: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

Many people have found the webstore version useful for doing some basic web development as an alternative to python -m SimpleHTTPServer. But it can also be used for quick file sharing over a local network.

Features

  • serve local files
  • configure listening port
  • configure listening interface (e.g. localhost or all interfaces)
  • custom http handlers possible
  • websocket support available
  • works nice with chrome.runtime.onSuspend
  • options for autostart, start in background, etc etc.
  • handles range requests, HEAD, etc
  • options for CORS
  • optional PUT, DELETE request (for upload files)
  • sets MIME types
  • can render directory listing
  • See relevant options: https://github.com/kzahel/web-server-chrome/blob/master/polymer-ui/options.js

How to include into your own chrome app

run minimize.sh to concatenate all the required files together and then include the resulting wsc-chrome.min.js in your project. Here is an example of another project's usage: https://github.com/zebradog/kiosk/blob/f7a398f697edc1c22b90c14f959779f1e850012a/src/js/main.js#L124

=== Basic usage:

var app = new WSC.WebApplication(options)
app.start( callback )

options: object, with keys

Handlers
    var handlers = [
        ['/favicon.ico',FavIconHandler],
        ['/stream.*',StreamHandler],
        ['/static/(.*)',StaticHandler],
        ['.*', DefaultHandler]
    ]

handlers is an array of 2 element arrays where the first item is a regular expression for the URL and the second is the handler class, which should extend WSC.BaseHandler

    function StaticHandler() {
        this.disk = null
        chrome.runtime.getPackageDirectoryEntry( function(entry) { this.disk = entry }.bind(this) )
        WSC.BaseHandler.prototype.constructor.call(this)
    }
    var FavIconHandlerprototype = {
        get: function(path) {
            // USE HTML5 filesystem operations to read file
            
        },
        onReadFile: function(evt) {
            if (evt.error) {
                this.write('disk access error')
            } else {
                this.write(evt)
            }
        }
    }
    _.extend(StaticHandler.prototype,
             StaticHandlerprototype,
             WSC.BaseHandler.prototype
            )

==== Building

Unfortunately there is a build process if you want to run this from source directly because I am using a Polymer (polymer-project.org) user interface. There is a bower.json in the polymer-ui folder and you will need to install node+npm+bower and then run bower install from that folder. Oh, and then you will need to "Refactor for CSP" (chrome apps do not allow inline scripts), one way of doing this is using https://chrome.google.com/webstore/detail/chrome-dev-editor-develop/pnoffddplpippgcfjdhbmhkofpnaalpg (open the folder and right click and select refactor for CSP)

I'm now using a script that can do this (look in polymer-ui/build.sh. You'll need to npm install -g vulcanize crisper)

====

Get it in the chrome web store: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

The default behavior right now is very simple. You choose a directory to serve static content. It is now able to stream large files and handle range requests. It also sets mime types correctly.

Here is an example project based on it: https://chrome.google.com/webstore/detail/flv-player/dhogabmliblgpadclikpkjfnnipeebjm

====

MIT license

I wrote this because the example app provided by google would lock and hang and had all sorts of nasty race conditions. Plus it would not stream large files or do range requests, HEAD requests, etc, etc.

The design of this is inspired heavily by to the Python Tornado Web library. In this as well as that, you create an "app" which registers handlers. Then under the hood it will accept connections, create an HTTPConnection object, and that has an associated IOStream object which handles the nonblocking read/write events for you.

See CREDITS file