Skip to content

Commit

Permalink
Add redirect logic for missing trailing slash, refactor example, demo…
Browse files Browse the repository at this point in the history
… screenshot
  • Loading branch information
humphd committed Jan 8, 2019
1 parent 0c003af commit 7e93f77
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 17 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ npm install
npm run dev
```

Open `http://localhost:1234/`, which will install the Service Worker. You can
then browse into the filesystem via `http://localhost:1234/fs/*`, where `/*` is
Open `http://localhost:8080/`, which will install the Service Worker. You can
then browse into the filesystem via `http://localhost:8080/fs/*`, where `/*` is
a path into the filesystem.

To get metadata about files/directories vs. contents, add `?json` to the URL.
For example: `http://localhost:1234/fs/dir?json`
For example: `http://localhost:8080/fs/dir?json`

To download instead of view files in the browser, add `?download` or `?dl` to the URL.
For example: `http://localhost:1234/fs/path/to/file.png?dl`
For example: `http://localhost:8080/fs/path/to/file.png?dl`

NOTE: I don't currently have a demo up, so the filesystem is empty. My plan
NOTE: I don't currently have a demo up, so the default 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.
self-hosting of static files in the browser. Here's what it looks like running
with a fileystem manually created:

![Example running](screenshots/demo.png)
1 change: 1 addition & 0 deletions src/index.html → example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>nohost</title>
</head>
<body>
<p>Browse filesystem at <a href="/fs">/fs</a></p>
<script src="./index.js"></script>
</body>
</html>
7 changes: 2 additions & 5 deletions src/index.js → example/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* eslint no-console:0 */

/**
* Register the nohost service worker, passing `route`
*/
if(!('serviceWorker' in navigator)) {
/* eslint no-console:0 */
console.log('[nohost] unable to initialize service worker: not supported.');
} else {
// TODO: make this something you can pass in via an api, init(route)
// const route = 'filer';

navigator.serviceWorker
// .register(`./nohost-sw.js?route=${encodeURIComponent(route)}`)
.register('./nohost-sw.js')
.catch(err => {
console.error(`[nohost] unable to register service worker: ${err.message}`);
Expand Down
Loading

0 comments on commit 7e93f77

Please sign in to comment.