Browse Source

docs.. examples

master
Lloyd Brookes 9 years ago
parent
commit
a5a1b6f9ec
  1. 33
      README.md
  2. 7
      example/simple/css/style.css
  3. 10
      example/simple/index.html
  4. 3
      example/spa/.local-web-server.json
  5. 0
      example/spa/css/style.css
  6. 2
      example/spa/index.html
  7. 33
      jsdoc2md/README.hbs
  8. 3
      test/fixture/spa/.local-web-server.json
  9. 1
      test/fixture/spa/one.html
  10. 4
      test/test.js

33
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).

7
example/simple/css/style.css

@ -0,0 +1,7 @@
body {
background-color: #AA3939;
color: #FFE2E2
}
svg {
fill: #000
}

10
example/simple/index.html

@ -0,0 +1,10 @@
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<h1>Amazing Page</h1>
<p>
With a freaky triangle..
</p>
<svg width="500" height="500">
<polygon points="250,0 0,500 500,500"></polygon>
</svg>

3
example/spa/.local-web-server.json

@ -0,0 +1,3 @@
{
"spa": "index.html"
}

0
test/fixture/spa/css/style.css → example/spa/css/style.css

2
test/fixture/spa/spa.html → example/spa/index.html

@ -1,5 +1,5 @@
<head>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<h1>Single Page App</h1>
<h2>Location: <span></span></h2>

33
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).

3
test/fixture/spa/.local-web-server.json

@ -1,3 +0,0 @@
{
"spa": "spa.html"
}

1
test/fixture/spa/one.html

@ -1 +0,0 @@
<h1>one</h1>

4
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')

Loading…
Cancel
Save