GithubHelp home page GithubHelp logo

kzahel / web-server-chrome Goto Github PK

View Code? Open in Web Editor NEW
1.2K 1.2K 274.0 974 KB

An HTTP Web Server for Chrome (chrome.sockets API)

Home Page: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

License: Other

JavaScript 89.45% HTML 9.83% Shell 0.22% CSS 0.06% Python 0.43%

web-server-chrome's Introduction

Try it now in CWS

Web Server for Chrome

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

cd web-server-chrome
mkdir assets
cd makedeps
npm install
npm run make # this builds the app dependencies such as react and material-ui into a bundle
cd ../react-ui
npm run watch # Press ctrl-c if you just want to build it once.
# press ctrl-C if you are done editing
cd ../
bash package.sh

This creates package.zip, which can then be distributed.

Where to get it

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

web-server-chrome's People

Contributors

ahmetkizilay avatar alas avatar danopia avatar kzahel avatar lon3wolf avatar mumme74 avatar oleg-khymchenko-kh avatar pier66 avatar scheinercc avatar sdegutis avatar sheepmaster avatar tantalor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

web-server-chrome's Issues

Support extensionless URLs

It would be wonderful if this project's server would support loading URLs without file extensions, once given a list of file extensions in its preferences for which to check. For instance, if the server was set to check for .html, .css, .svg, then when attempting to load /bar/foo, it would first check for /bar/foo.html, then /bar/foo.css, then /bar/foo.svg.

I have a need for this because my production servers use extensionless URLs—this is a great project, but I cannot use it if it doesn't support them. After all, as Tim Berners-Lee says, good URLs don't have file extensions.

nubie

I am getting into github, I have to tred carefully because i never got into this techonology venture. i hope to achive something here.

Autostart

Hi, great App, it does exactly what i need. Just one wish: it would be great, if i could define, that the app starts automaticly at browser-start. Dont know, if this is possible in Chrome.

Server not working from cloned repo

Server did not worked when cloned the repo.It worked well when I installed the app from chrome web store.
I want change the IP and PORT address, so tried to get it work from cloned repo.

Is https possible?

I think I might already know the answer to this but wanted to know if you had any ideas on how we could get ssl working. I'm not sure if chrome supports it.

Folder listing on folders

When I visit the folder that I've specified I expect to see a folder listing of files in that directory (similar to the default behaviour of Apache on most OSes). Instead it just "spins".

To see a file I have to specify the full path to the file e.g. http://127.0.0.1:8887/myfile.html

I'm on a Chromebook specifically: Version 35.0.1916.155, Platform 5712.89.0 (Official Build) stable-channel peppy, Firmware Google_Peppy.4389.84.0 (if that makes a difference).

Web server not working with JSTorrent

Steps to reproduce:

  1. Download, extract, and load JSTorrent master (Github) on Chrome
  2. Download and extract web-server-chrome master (Github) content to {foldername}\js\web-server-chrome
  3. Launch JSTorrent, go to options and enable web server
  4. Go to Extensions and reload JSTorrent
  5. Visit http://localhost:8543/ > ERR_CONNECTION_REFUSED
  6. Disabled uBlock/Tampermonkey extensions and Web-Server-Chrome app, relaunched Chrome and JSTorrent
  7. Re-visited http://localhost:8543/ > Still ERR_CONNECTION_REFUSED

NOTE: Web server from Chrome store works just fine.

How do I fix it?

Support for all Uncommon, yet Compliant Filename Characters in Windows OS

Congrats in your Web Server Chrome App!

I was running a few quick tests with your app and I think it is wonderful! Kudos! 👍

I think your APP has the potential to be a must-have for every web developer in the World, and maybe even for other non-technical people that would see the value in a tool (that syncs for free) and would allow them the freedom to run Apps like https://laverna.cc (you should know, it ran perfect in your app) in Chrome, but the data through another sync service of their choosing. Let me quickly run by you a few points before I run out the door.

  1. It took about a half a second to render a file list (when not using an index.html) of 1220 long-named *.txt and *.md files in a folder where I keep my Notation File System.
  2. I was not expecting that kind of performance.

Checkout out the results generated by this extension:

Event When HowLong Sum
Redirect 0 0 0
DNS 0 0 0
Connect 0 0 0
Request 5 39 39
Response 44 79 118
DOM 71 477 595
Interactive 413 0 -
ContentLoaded 413 15 -
LoadEvent 548 1 596
  1. I was able to successfully see *.txt files and *.MD files (with a markdown previewer extension) right on the browser, as I wanted too, which is excellent.
  2. Here comes the bit "but"... The app gave the following error on the other uncommon, yet "legal" file names, as though they didn't exist:

"entry not found"

  1. It looks like your server app is OK with with files named:

WebServerForChrome[@copy[01].MG.txt
WebServerForChrome.MG.md

  1. But not with these:

+WebServerForChrome@Copy[01].MG.txt
_WebServerForChrome[@copy[01].MG.txt
@WebServerForChrome[@copy[02].MG.txt
$WebServerForChrome.MG[@copy[03].MG.txt

WebServerForChrome.[@copy[04].MG.txt

It looks like a simple encoding issue, right?

  1. Unfortunately 90+% my notation files make use of characters like: ()[]+-#,@$. Which would be a bummer… Do you think if image, css, js, and other related website related files are named similarly the app will then too fail to render them?
  2. I understand my naming convention is quite unorthodox, however Windows does considers them "legal" and normally don't have any issues with them.
  3. In any case, thank you for the developing the APP and I think I may be able to help you in a few areas, would you mind telling me what you envision with the APP?

Take care,

Sylvia

Cannot wget a 3.5GB file from this webserver

I'm using this excellent little webserver for chef development and I believe I found a file too big for this webserver to serve. I've successfully done wget from VMs for files up to ~2.9GB, but I have a file that is 3.5GB that comes across as 0 size on the VMs.

Below is the 2.9GB file:
$ wget http://#.#.#.#:8887/oracleHome121024ee.tgz
--2015-10-22 20:00:33-- http://#.#.#.#:8887/oracleHome121024ee.tgz
Connecting to #.#.#.#:8887... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3141285114 (2.9G)
Saving to: “oracleHome121024ee.tgz”

0% [ ] 16,584,957 2.21M/s eta 25m 23s ♥

Following is the 3.5GB file
$ wget http://#.#.#.#:8887/gridHome121024.tgz
--2015-10-22 20:11:02-- http://#.#.#.#:8887/gridHome121024.tgz
Connecting to #.#.#.#:8887... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0
Saving to: “gridHome121024.tgz”

[ <=>                                                                                       ] 0           --.-K/s   in 0s

2015-10-22 20:11:02 (0.00 B/s) - “gridHome121024.tgz” saved [0/0]

The 3.5GB file successfully downloads from a webdav, but it is horribly slow compared to having this happen between two SSDs on my workstation.

Any chance of removing or bumping up this limit?

Do not cache content-length response header

After a file is served, any changes to the local file system are not reflected in the response header for content-length. This results in larger files being cut off.

Steps to reproduce

  1. Create file example.txt with the text: Hello World
  2. Open Developer Tools in Chrome CTRL + SHIFT + I
  3. View the network tab
  4. Go to http://127.0.0.1:8887/example.txt
  5. View the response headers of the page by clicking on the file name in the network tab
  6. Notice the response header for content-length is 11
  7. Change the text file to Hello My Friend
  8. Refresh the web page

Current Behavior

  1. The web page now says Hello My Fr
  2. The response header for content-length still says 11
  3. Stopping and starting the web server does not fix the problem

Expected Behavior

  1. The web page displays the full content of the file
  2. The response header for content-length returns the actual file size (15 bytes)
  3. Changing the file when the web server is not running will show the new content when the web server is started

Workaround

Click choose folder and pick the same folder.

web-server-chrome

Great little app but for me it does not run when the browser (chrome) is running in the background.

Can I use the server for hosting games on Facebook?

To whom it may concern,
I wanted to know, if I can use the program to serve on Facebook?
I was looking into using this app for hosting games.
Is there any advice or suggestions to what I can do?
Thanks,
islandlover1980

wrong responseLength with text response containing multi-byte characters

In webapp.js, the write() function of BaseHandler calculates the length of data as (data.length || data.byteLength). If data is a string containing multi-byte characters like those of a language other than English, the result will be wrong. String.length returns codepoint count rather than byte length, so part of the response will be cut off during transmission and the client will receive incomplete pages.

What makes this worse is that (AFAIK) javascript does not have a native function to get a string's byte length. Currently I work this around by omitting the response length and terminating the connection after all the data are transmitted. To get the real length of the data being send may involve some heavy coding to convert the data into a byte array and then determine its length. Curse Javascript :(

Cached file entries get cut off [Serving from Google Drive]

Steps to reproduce:

  1. Serve a directory from Google Drive through the Files app on Chrome OS
  2. Open any file from the directory over HTTP
  3. Change the file by making it longer
  4. Reload the file

Result:
The returned file gets cut off after the first n bytes, where n is the initial length of the file. If you change something in the first n bytes, the returned file will reflect those changes, but the file will always be cut off after n bytes.

From what I could gather by debugging, an old File object is cached in the entryFileCache and does not get invalidated when the file is changed (in contrast to the comment in EntryCache.get()). The actual file contents are still read freshly from disk, but because the old File object contains the old file size, only that number of bytes is read.

Given that the actual file contents are still read from disk, is there really much to be gained from caching the File objects at all?

Impossible to run in background

When I check the "Run in background" checkbox and close the "Web Server For Chrome" window of your extension. My website on http://127.0.0.1:8887/ still works for a while, but after some time (e.g. after a minute) if you reload the page, Chrome shows "ERR_CONNECTION_REFUSED".

Can you fix it, so the window of your plugin does not have to be open constantly in a task bar?

how to change the port?

I installed the app from chrome webstore, but I found that there is no way to set the port number.

eric

gestion d'une base de donnée

Loading files is too slow

I used to use Chrome with --disable-web-security parameter for testing my webapps locally. Local HTTP server is much better solution, so I decided to use yours.

My webapp loads large files using XMLHttpRequest. Loading 20 MB file when running from file:/// used to take less than a second (I have SSD drive), now using your HTTP server it takes about 5 seconds. Can you make it work faster?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.