diff --git a/README.md b/README.md index 35c8072..47d9b59 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,31 @@ A simple web-server for productive front-end development. **Requires node v4.0.0 or higher**. ## Synopsis +Some typical use cases.. -Serve a directory on the default port: +### Static site +Fire up your site on the default port: ```sh +$ tree +. +├── css +│   └── style.css +└── index.html + $ ws serving at http://localhost:8000 ``` +### Single Page Application + +Mark `index.html` as an SPA with client-side routing. +```sh +$ ws --spa index.html +``` + +With this option, routes with existing files (e.g. `/css/style.css`) will be served normally as static assets. Routes without an existing file (e.g. `/user/1`, `/login` etc.) are passed directly to your SPA. Without this option they would 404. + + Blacklist certain paths, for example config files: ```sh $ ws --forbid .json .yml @@ -28,11 +46,17 @@ Reduce bandwidth with gzip compression: $ ws --compress ``` -Specify a Single Page Application: +When urls don't map to your directory structure, rewrite: ```sh -$ ws --spa index.html +$ ws --rewrite /css=>/build/css +``` + +Rewrite to remote servers: +```sh +$ ws --rewrite /api=>http://api.example.com/api /npm=>http://registry.npmjs.com ``` + ## Install Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`. @@ -116,6 +140,9 @@ You can set additional mime-type/extension mappings, or override the defaults by } ``` +## Use with Google DevTools Workspaces + + ## Log Visualisation Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation). diff --git a/example/simple/css/style.css b/example/simple/css/style.css new file mode 100644 index 0000000..7fb71e5 --- /dev/null +++ b/example/simple/css/style.css @@ -0,0 +1,7 @@ +body { + background-color: #AA3939; + color: #FFE2E2 +} +svg { + fill: #000 +} diff --git a/example/simple/index.html b/example/simple/index.html new file mode 100644 index 0000000..008f97d --- /dev/null +++ b/example/simple/index.html @@ -0,0 +1,10 @@ + + + +

Amazing Page

+

+ With a freaky triangle.. +

+ + + diff --git a/example/spa/.local-web-server.json b/example/spa/.local-web-server.json new file mode 100644 index 0000000..2c63606 --- /dev/null +++ b/example/spa/.local-web-server.json @@ -0,0 +1,3 @@ +{ + "spa": "index.html" +} diff --git a/test/fixture/spa/css/style.css b/example/spa/css/style.css similarity index 100% rename from test/fixture/spa/css/style.css rename to example/spa/css/style.css diff --git a/test/fixture/spa/spa.html b/example/spa/index.html similarity index 77% rename from test/fixture/spa/spa.html rename to example/spa/index.html index 94a709a..c2d71a9 100644 --- a/test/fixture/spa/spa.html +++ b/example/spa/index.html @@ -1,5 +1,5 @@ - +

Single Page App

Location:

diff --git a/jsdoc2md/README.hbs b/jsdoc2md/README.hbs index cefdbe9..3d7ca17 100644 --- a/jsdoc2md/README.hbs +++ b/jsdoc2md/README.hbs @@ -10,13 +10,31 @@ A simple web-server for productive front-end development. **Requires node v4.0.0 or higher**. ## Synopsis +Some typical use cases.. -Serve a directory on the default port: +### Static site +Fire up your site on the default port: ```sh +$ tree +. +├── css +│   └── style.css +└── index.html + $ ws serving at http://localhost:8000 ``` +### Single Page Application + +Mark `index.html` as an SPA with client-side routing. +```sh +$ ws --spa index.html +``` + +With this option, routes with existing files (e.g. `/css/style.css`) will be served normally as static assets. Routes without an existing file (e.g. `/user/1`, `/login` etc.) are passed directly to your SPA. Without this option they would 404. + + Blacklist certain paths, for example config files: ```sh $ ws --forbid .json .yml @@ -28,11 +46,17 @@ Reduce bandwidth with gzip compression: $ ws --compress ``` -Specify a Single Page Application: +When urls don't map to your directory structure, rewrite: ```sh -$ ws --spa index.html +$ ws --rewrite /css=>/build/css +``` + +Rewrite to remote servers: +```sh +$ ws --rewrite /api=>http://api.example.com/api /npm=>http://registry.npmjs.com ``` + ## Install Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`. @@ -116,6 +140,9 @@ You can set additional mime-type/extension mappings, or override the defaults by } ``` +## Use with Google DevTools Workspaces + + ## Log Visualisation Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation). diff --git a/test/fixture/spa/.local-web-server.json b/test/fixture/spa/.local-web-server.json deleted file mode 100644 index 881eafa..0000000 --- a/test/fixture/spa/.local-web-server.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "spa": "spa.html" -} diff --git a/test/fixture/spa/one.html b/test/fixture/spa/one.html deleted file mode 100644 index 0f04799..0000000 --- a/test/fixture/spa/one.html +++ /dev/null @@ -1 +0,0 @@ -

one

diff --git a/test/test.js b/test/test.js index 46e954a..43d5d6f 100644 --- a/test/test.js +++ b/test/test.js @@ -101,12 +101,12 @@ test('mime', function(t){ }}) }) -test('blacklist', function (t) { +test('forbid', function (t) { t.plan(2) const app = localWebServer({ log: { format: 'none' }, static: { root: __dirname + '/fixture' }, - blacklist: [ /php$/, /html$/ ] + forbid: [ /php$/, /html$/ ] }) const server = launchServer(app, { leaveOpen: true }) request('http://localhost:8100/something.php')