• Stars
    star
    260
  • Rank 157,189 (Top 4 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A web server in your web browser

nohost

A web server in your web browser.

Overview

nohost uses Filer to run a node'js style, POSIX filesystem inside a Service Worker, and handle requests for static files and directories.

The most likely use case for nohost would be an app that uses Filer to run a filesystem in the window, and then use nohost to provide a way to interact with that filesystem in the browser via URLs, like one would with Apache or another web server hosting static files.

Example

NOTE: I don't currently have a full demo up (TODO), so the default filesystem is empty. My plan is to rework this into a module people can include along with Filer to allow self-hosting of static files in the browser.

Until then, here's what nohost looks like running with a fileystem manually created:

Example running

Clicking a link does what you'd expect, serving the file to the browser via the Service Worker.

Installation

To run it:

npm install
npm run build

The nohost Service Worker will be built in dist/nohost-sw.js. NOTE: you can also use npm run dev to also start a web server.

Now register nohost's Service Worker in your app at startup:

if(!('serviceWorker' in navigator)) {
  console.warn('unable to initialize nohost service worker: not supported.');
} else {
  navigator.serviceWorker
    .register('./nohost-sw.js') // see configuration options below
    .catch(err => {
      console.error(`unable to register nohost service worker: ${err.message}`);
    });
}

Configure Web Server

Various features of the nohost web server can be configured by passing options on the query string when registering the nohost-sw.js Service Worker:

  • route (String): with the route name to use when listening for filesystem path requests. Defaults to fs, such that /fs/path/to/file would respond with /path/to/file

  • disableIndexes (Boolean, present or absent): directory indexes (i.e., listings) will not be shown. By default they will be shown. If defined, users will have to know the filename they wish to get back from the server.

  • directoryIndex (String): overrides the default directory index filename, used when a directory path is given. Defautls to index.html. For example, /fs/ would return /fs/index.html by default (if present). If another name is specified here, that filename will be used instead.

For example:

// Use /www for the server route, and disable directory listings
navigator.serviceWorker
  .register('./nohost-sw.js?route=www&disableIndexes');

Browse Filesystem

After the Service Worker is installed, you can then browse into the filesystem via the specified route (defaults to /fs/*). For example, if running the demo: 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:8080/fs/dir?json

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

More Repositories

1

have-fun-with-machine-learning

An absolute beginner's guide to Machine Learning and Image Classification with Neural Networks
Python
5,064
star
2

browser-shell

A Linux command-line shell in the browser
HTML
259
star
3

VncSharp

VncSharp is a GPL implementation of the VNC Remote Framebuffer (RFB) Protocol for the .NET Framework
C#
222
star
4

browser-vm

A small Linux x86 VM meant for use in the browser
Dockerfile
140
star
5

sfxr.js

JavaScript port of SFXR, video game sound effect generator
JavaScript
29
star
6

hacktoberfest-at-seneca-2018

Tracking and Support for Hacktoberfest 2018 at Seneca College
16
star
7

browser-mime

MIME types for use in browsers
JavaScript
16
star
8

next

What I'm doing next (name TBD)
JavaScript
14
star
9

learn-travis

An example to show how to get TravisCI integrated into a node.js project
JavaScript
10
star
10

snowy-owls-ca

Tracking Snowy Owls Across Canada
JavaScript
7
star
11

node-webvtt

A command line interface and npm package for the WebVTT JavaScript parser.
JavaScript
6
star
12

SpecialPowers

Mozilla SpecialPowers testing extension
JavaScript
5
star
13

node-eden

Name generator
JavaScript
5
star
14

Seneca2017LearningLab

A repo for DPS909/OSD600 students to learn open source tooling
JavaScript
4
star
15

purl

Pretty print the contents of a resource at a URL
JavaScript
4
star
16

bridge-troll

Collect all the trolls living under Ontario's bridges
JavaScript
3
star
17

unicode

Unicode Dance Party
HTML
3
star
18

openai-form-example

Working with OpenAI and HTML Forms
HTML
3
star
19

Video-Stats

HTML5 Video painting performance statistics for Firefox 5 video
JavaScript
3
star
20

git-idfs-db

A git db implementation that wraps an IDBFS interface instance. Creates real git repos in the fs.
JavaScript
2
star
21

brackets-5ialog

HTML5 File Dialogs for Brackets
JavaScript
2
star
22

amore.webmaker.org

Webmaker localization app
JavaScript
2
star
23

node-bugzilla

A node module to make filing bugs in node apps easy
JavaScript
2
star
24

web422-week12

WebSockets Emoji Chat App Server and React Client
JavaScript
1
star
25

recreate-newyorker-css

Recreating a New Yorker web page's text styles in HTML and CSS
HTML
1
star
26

recreate-youtube-css

Recreating the YouTube search results page's CSS styles in HTML and CSS
HTML
1
star
27

aparecium

A charm to reveal secret messages
JavaScript
1
star
28

bitjs

Automatically exported from code.google.com/p/bitjs
JavaScript
1
star
29

pretty-effective

An Analysis of the Prettier Project
1
star
30

pdfjs-express-example

Minimal example of serving a PDF file from express to the browser and rendering with PDF.js
JavaScript
1
star
31

aws-learner-lab-utils

Various scripts, utils, and tools for using the AWS Learner Lab
JavaScript
1
star