use module-dir
This commit is contained in:
18
README.md
18
README.md
@ -5,28 +5,28 @@
|
|||||||
[](https://github.com/feross/standard)
|
[](https://github.com/feross/standard)
|
||||||
[](https://gitter.im/lwsjs/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/lwsjs/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
***Requires node v7.6 or higher. Install the [previous release](https://github.com/lwsjs/local-web-server/tree/v1.x) for older node support. Documentation still WIP.***
|
***Requires node v7.6 or higher. Install the [previous release](https://github.com/lwsjs/local-web-server/tree/v1.x) for node >= v4.0.0. Documentation still WIP.***
|
||||||
|
|
||||||
# local-web-server
|
# local-web-server
|
||||||
|
|
||||||
The productive development web server. Built on [lws](https://github.com/lwsjs/lws).
|
The development web server for productive front-end and full-stack Javascript engineers. Built on [lws](https://github.com/lwsjs/lws).
|
||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
|
|
||||||
- Fast and lightweight. Supports most common web application styles:
|
- Fast and lightweight.
|
||||||
- Static site.
|
- Use the built-in features, a subset of the built-ins or your own feature stack
|
||||||
- Single Page Application (client-side rendering, web service consumption).
|
- Configurable with sensible defaults.
|
||||||
- Server-rendered content.
|
- Configure by constructor option, command-line option, stored config or all three.
|
||||||
- Configurable with sensible defaults. Configure by constructor option, command-line option, stored config or all three.
|
|
||||||
- HTTP or HTTPS ([HTTP2](https://github.com/nodejs/http2) will be added once ready)
|
- HTTP or HTTPS ([HTTP2](https://github.com/nodejs/http2) will be added once ready)
|
||||||
- URL rewriting
|
- URL rewriting
|
||||||
- Local rewrites for quick experimentation (e.g. from `/img/logo.svg` to `/img/new-logo.svg`)
|
- Local rewrites for quick experimentation (e.g. from `/img/logo.svg` to `/img/new-logo.svg`)
|
||||||
- Rewrite to remote resources (e.g. from `/api/*` to `https://example-api.pl/api/$1`). *Note: ignores remote server's CORS policy, which during development is typically what you want*.
|
- Rewrite to remote resources (e.g. from `/api/*` to `https://example-api.pl/api/$1`). *Note: ignores remote server's CORS policy, which during development is typically what you want*.
|
||||||
- Optimised default caching strategy. Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
|
- Optimisal caching by default.
|
||||||
|
- Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
|
||||||
- Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/lwsjs/local-web-server/blob/master/doc/visualisation.md)
|
- Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/lwsjs/local-web-server/blob/master/doc/visualisation.md)
|
||||||
- Configurable CORS rules. All origins allowed by default.
|
- Configurable CORS rules. All origins allowed by default.
|
||||||
|
|
||||||
**Use cases**
|
**Links to demoes and how-tos**
|
||||||
|
|
||||||
Things you can build:
|
Things you can build:
|
||||||
|
|
||||||
|
11
bin/cli.js
11
bin/cli.js
@ -2,4 +2,13 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const LocalWebServer = require('../')
|
const LocalWebServer = require('../')
|
||||||
const localWebServer = new LocalWebServer()
|
const localWebServer = new LocalWebServer()
|
||||||
localWebServer.start()
|
try {
|
||||||
|
localWebServer.start()
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 'MODULE_NOT_FOUND') {
|
||||||
|
console.error(err.message)
|
||||||
|
console.error(require('util').inspect(err.attempted, { depth: 6, colors: true }))
|
||||||
|
} else {
|
||||||
|
console.error(err.stack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@ const Lws = require('lws')
|
|||||||
class LocalWebServer extends Lws {
|
class LocalWebServer extends Lws {
|
||||||
constructor (options) {
|
constructor (options) {
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const stack = [
|
let stack = [
|
||||||
'lws-log',
|
'lws-log',
|
||||||
'lws-cors',
|
'lws-cors',
|
||||||
'lws-json',
|
'lws-json',
|
||||||
@ -25,10 +25,9 @@ class LocalWebServer extends Lws {
|
|||||||
'lws-spa',
|
'lws-spa',
|
||||||
'lws-static',
|
'lws-static',
|
||||||
'lws-index'
|
'lws-index'
|
||||||
].map(name => {
|
]
|
||||||
return path.resolve(__dirname, `../node_modules/${name}`)
|
const moduleDir = path.resolve(__dirname, `../node_modules`)
|
||||||
})
|
options = Object.assign({ stack, 'module-dir': moduleDir, prefix: 'lws-' }, options)
|
||||||
options = Object.assign({ stack }, options)
|
|
||||||
super(options)
|
super(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user