Browse Source

readme, docs, deps

master
Lloyd Brookes 8 years ago
parent
commit
34373217ec
  1. 4
      README.md
  2. 12
      lib/local-web-server.js
  3. 18
      package.json

4
README.md

@ -56,7 +56,9 @@ Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:80
By default, requests for typical SPA paths (e.g. `/user/1`, `/login`) return `404 Not Found` as a file at that location does not exist. By marking `index.html` as the SPA you create this rule: By default, requests for typical SPA paths (e.g. `/user/1`, `/login`) return `404 Not Found` as a file at that location does not exist. By marking `index.html` as the SPA you create this rule:
*If a static file at the requested path exists (e.g. `/css/style.css`) then serve it, if it does not (e.g. `/login`) then serve the specified SPA and handle the route client-side.*
*If a static file is requested (e.g. `/css/style.css`) then serve it, if not (e.g. `/login`) then serve the specified SPA and handle the route client-side.*
[Read more](https://github.com/lwsjs/local-web-server/wiki/How-to-serve-a-Single-Page-Application-(SPA)).
### URL rewriting and proxied requests ### URL rewriting and proxied requests

12
lib/local-web-server.js

@ -7,9 +7,13 @@ const path = require('path')
* const LocalWebServer = require('local-web-server') * const LocalWebServer = require('local-web-server')
* const localWebServer = new LocalWebServer() * const localWebServer = new LocalWebServer()
* const server = localWebServer.listen({ * const server = localWebServer.listen({
* port: port,
* directory: 'src'
* port: 8050,
* https: true,
* directory: 'src',
* spa: 'index.html',
* websocket: 'src/websocket-server.js'
* }) * })
* // secure, SPA server with listening websocket now ready on port 8050
*/ */
/** /**
@ -17,7 +21,7 @@ const path = require('path')
*/ */
class LocalWebServer extends Lws { class LocalWebServer extends Lws {
/** /**
* Create a listening HTTP/HTTPS server.
* Returns a listening HTTP/HTTPS server.
* @param [options] {object} - Server options * @param [options] {object} - Server options
* @param [options.port] {number} - Port * @param [options.port] {number} - Port
* @param [options.hostname] {string} -The hostname (or IP address) to listen on. Defaults to 0.0.0.0. * @param [options.hostname] {string} -The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
@ -33,7 +37,7 @@ class LocalWebServer extends Lws {
* @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class. * @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class.
* @param [options.server] {string|ServerFactory} - Custom server factory, e.g. lws-http2. * @param [options.server] {string|ServerFactory} - Custom server factory, e.g. lws-http2.
* @param [options.websocket] {string|Websocket} - Path to a websocket module * @param [options.websocket] {string|Websocket} - Path to a websocket module
* @param [options.moduleDir] {string[]} - One or more directories to search for feature modules.
* @param [options.moduleDir] {string[]} - One or more directories to search for modules.
* @returns {Server} * @returns {Server}
*/ */
listen (options) { listen (options) {

18
package.json

@ -33,19 +33,19 @@
"author": "Lloyd Brookes <75pound@gmail.com>", "author": "Lloyd Brookes <75pound@gmail.com>",
"dependencies": { "dependencies": {
"lws": "^1.0.0-pre4.0", "lws": "^1.0.0-pre4.0",
"lws-blacklist": "^0.2.1",
"lws-blacklist": "^0.2.3",
"lws-body-parser": "^0.2.4", "lws-body-parser": "^0.2.4",
"lws-compress": "^0.2.1", "lws-compress": "^0.2.1",
"lws-conditional-get": "^0.3.3", "lws-conditional-get": "^0.3.3",
"lws-cors": "^0.3.2",
"lws-index": "^0.3.2",
"lws-cors": "^0.3.4",
"lws-index": "^0.3.3",
"lws-json": "^0.3.2", "lws-json": "^0.3.2",
"lws-log": "^0.3.1",
"lws-mime": "^0.2.1",
"lws-mock-response": "^0.4.0",
"lws-request-monitor": "^0.1.3",
"lws-rewrite": "^0.3.5",
"lws-spa": "^0.2.2",
"lws-log": "^0.3.2",
"lws-mime": "^0.2.2",
"lws-mock-response": "^0.4.2",
"lws-request-monitor": "^0.1.4",
"lws-rewrite": "^0.3.6",
"lws-spa": "^0.2.3",
"lws-static": "^0.4.1" "lws-static": "^0.4.1"
}, },
"devDependencies": { "devDependencies": {

Loading…
Cancel
Save