Skip to content

Commit

Permalink
Rewrite to use new Filer and run in a Service Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Jan 5, 2019
1 parent eea1087 commit dced878
Show file tree
Hide file tree
Showing 26 changed files with 8,152 additions and 2,360 deletions.
37 changes: 37 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"mocha": true,
"node": true,
"worker": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"eqeqeq": [
"error",
"always"
]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*~
node_modules
.cache
dist
20 changes: 0 additions & 20 deletions Gruntfile.js

This file was deleted.

51 changes: 14 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
nohost
======

A web server in your web browser.

Running a local web server allows for easier testing and development without the need for a network. The nohost web server takes this a step futher, and allows web sites to be hosted inside the browser without any server or network.

nohost was created in order to make it easier to do in browser, live previews of complex web sites and applications
that span many files.

###Demo

You can try a [demo here](http://humphd.github.io/nohost).

Like any web server, you must first install what you want to serve. The nohost server uses [Filer](https://github.com/js-platform/filer) in order to create a filesystem within the browser.
Files are then installed in the filesystem using the `?install` boot option, and choosing a disk
image (*.zip). A demo disk image is included, which can be installed by doing the following:

[http://humphd.github.io/nohost?install=webmaker-kits-gh-pages.zip](http://humphd.github.io/nohost?install=webmaker-kits-gh-pages.zip)

Once installed, the filesystem will survive the server being started and stopped (i.e., closing the window).
If you want to clear the filesystem, use the `?reset` boot option:

[http://humphd.github.io/nohost?reset](http://humphd.github.io/nohost?reset)

Now that files are installed into the fileystem, you can browse them by adding a path to the query string:

* Web Root - [http://humphd.github.io/nohost?/](http://humphd.github.io/nohost?/)
* An HTML page - [http://humphd.github.io/nohost/?/webmaker-kits-gh-pages/kit.html](http://humphd.github.io/nohost/?/webmaker-kits-gh-pages/kit.html)

Any path not found in the filesystem will produce a 404:
This uses [Filer](https://github.com/filerjs/filer) to run a node'js style
POSIX filesystem inside a Service Worker, and handle requests for static files and
directories.

[http://humphd.github.io/nohost/?/nothere](http://humphd.github.io/nohost/?/nothere)
To run it:

###How it Works
```
npm install
npm run dev
```

nohost boots the web server whenever you load its `index.html` page. Boot options are read from the query string
and then actions are taken using the filesystem. Since the filesystem survives between executions of the page,
there is stability between various requests.
Open `http://localhost:1234/`, which will install the Service Worker. You can
then browse into the filesystem via `http://localhost:1234/fs/*`, where `/*` is
a path into the filesystem.

Each request for a path involves rewriting. The file at a given path is read and parsed, and processed so as to
inline any external resources (e.g., images, stylesheets, etc). When the document is done being processed,
it is again turned into text, and `document.write` is used to replace the web server's boot page with the new content. Some special pages are synthesized, similar to how a normal web server works. For example: directory listings and images.
NOTE: I don't currently have a demo up, so the filesystem is empty. My plan
is to rework this into a module you can include along with Filer to allow
self-hosting of static files in the browser.
63 changes: 0 additions & 63 deletions index.html

This file was deleted.

Loading

0 comments on commit dced878

Please sign in to comment.