Browse Source

update stack examples and deps

master
Lloyd Brookes 9 years ago
parent
commit
99f5b19d27
  1. 3
      example/custom/cache-control/.local-web-server.json
  2. 18
      example/custom/cache-control/server.js
  3. 19
      example/custom/live-reload-optional/server.js
  4. 9
      example/custom/live-reload/server.js
  5. 12
      example/stack/cache-control.js
  6. 2
      example/stack/live-reload-optional/index.html
  7. 24
      example/stack/live-reload-optional/stack.js
  8. 0
      example/stack/live-reload/index.html
  9. 14
      example/stack/live-reload/stack.js
  10. 3
      lib/local-web-server.js
  11. 31
      package.json

3
example/custom/cache-control/.local-web-server.json

@ -1,3 +0,0 @@
{
"maxage": 2000
}

18
example/custom/cache-control/server.js

@ -1,18 +0,0 @@
'use strict'
const LocalWebServer = require('../../')
const cacheControl = require('koa-cache-control')
const ws = new LocalWebServer()
ws.addLogging('dev')
.add({
optionDefinitions: {
name: 'maxage', type: Number,
description: 'The maxage to set on each response.'
},
middleware: function (options) {
return cacheControl({ maxAge: options.maxage })
}
})
.addStatic()
.addIndex()
.listen()

19
example/custom/live-reload-optional/server.js

@ -1,19 +0,0 @@
'use strict'
const Cli = require('../../')
const liveReload = require('koa-livereload')
const ws = new Cli()
ws.addLogging('dev')
.add({
optionDefinitions: {
name: 'live-reload', type: Boolean,
description: 'Add live reload.'
},
middleware: function (options) {
if (options['live-reload']) {
return liveReload()
}
}
})
.addStatic()
.listen()

9
example/custom/live-reload/server.js

@ -1,9 +0,0 @@
'use strict'
const Cli = require('../../')
const liveReload = require('koa-livereload')
const ws = new Cli()
ws.addLogging('dev')
.add({ middleware: liveReload })
.addStatic()
.listen()

12
example/stack/cache-control.js

@ -5,8 +5,13 @@ const DefaultStack = require('local-web-server-default-stack')
class CacheControl extends DefaultStack { class CacheControl extends DefaultStack {
addAll () { addAll () {
this.addLogging('dev')
.add({
return this.addLogging('dev')
.addCacheControl()
.addStatic()
.addIndex()
}
addCacheControl () {
this.add({
optionDefinitions: { optionDefinitions: {
name: 'maxage', type: Number, name: 'maxage', type: Number,
description: 'The maxage to set on each response.' description: 'The maxage to set on each response.'
@ -15,8 +20,7 @@ class CacheControl extends DefaultStack {
return cacheControl({ maxAge: options.maxage }) return cacheControl({ maxAge: options.maxage })
} }
}) })
.addStatic()
.addIndex()
return this
} }
} }

2
example/custom/live-reload/index.html → example/stack/live-reload-optional/index.html

@ -5,6 +5,6 @@
<title>live-reload demo</title> <title>live-reload demo</title>
</head> </head>
<body> <body>
<h1>Live reloaded attached</h1>
<h1>Live reloaded potentially attached</h1>
</body> </body>
</html> </html>

24
example/stack/live-reload-optional/stack.js

@ -0,0 +1,24 @@
'use strict'
const LocalWebServer = require('../../../')
const liveReload = require('koa-livereload')
const DefaultStack = require('local-web-server-default-stack')
class LiveReloadStack extends DefaultStack {
addAll () {
return this.addLogging('dev')
.add({
optionDefinitions: {
name: 'live-reload', type: Boolean,
description: 'Add live reload.'
},
middleware: function (options) {
if (options['live-reload']) {
return liveReload()
}
}
})
.addStatic()
}
}
module.exports = LiveReloadStack

0
example/custom/live-reload-optional/index.html → example/stack/live-reload/index.html

14
example/stack/live-reload/stack.js

@ -0,0 +1,14 @@
'use strict'
const LocalWebServer = require('../../../')
const liveReload = require('koa-livereload')
const DefaultStack = require('local-web-server-default-stack')
class LiveReloadStack extends DefaultStack {
addAll () {
return this.addLogging('dev')
.add({ middleware: liveReload })
.addStatic()
}
}
module.exports = LiveReloadStack

3
lib/local-web-server.js

@ -5,7 +5,6 @@ const path = require('path')
const arrayify = require('array-back') const arrayify = require('array-back')
const t = require('typical') const t = require('typical')
const CommandLineTool = require('command-line-tool') const CommandLineTool = require('command-line-tool')
const DefaultStack = require('local-web-server-default-stack')
/** /**
* @module local-web-server * @module local-web-server
@ -30,7 +29,7 @@ class LocalWebServer {
if (/^-/.test(stackPath)) stackPath = null if (/^-/.test(stackPath)) stackPath = null
} }
const stackModule = loadStack(stackPath) || DefaultStack
const stackModule = loadStack(stackPath) || require('local-web-server-default-stack')
this.stack = new stackModule() this.stack = new stackModule()
this.stack.addAll() this.stack.addAll()
const middlewareOptionDefinitions = this.stack.getOptionDefinitions() const middlewareOptionDefinitions = this.stack.getOptionDefinitions()

31
package.json

@ -34,38 +34,19 @@
"dependencies": { "dependencies": {
"ansi-escape-sequences": "^2.2.2", "ansi-escape-sequences": "^2.2.2",
"array-back": "^1.0.3", "array-back": "^1.0.3",
"command-line-tool": "~0.3.0",
"config-master": "^2.0.2",
"http-proxy": "^1.13.3",
"kcors": "^1.2.1",
"command-line-tool": "~0.3.1",
"config-master": "^2.0.3",
"koa": "^2.0.0", "koa": "^2.0.0",
"koa-bodyparser": "^3.0.0",
"koa-compose": "^3.1.0",
"koa-compress": "^1.0.9",
"koa-conditional-get": "^1.0.3",
"koa-convert": "^1.2.0",
"koa-etag": "^2.1.1",
"koa-json": "^1.1.3",
"koa-mock-response": "0.0.2",
"koa-morgan": "^1.0.1",
"koa-rewrite": "^2.1.0",
"koa-route": "^3.0.0",
"koa-send": "^3.2.0",
"koa-serve-index": "^1.1.1",
"koa-static": "^2.0.0",
"local-web-server-stack": "github:75lb/local-web-server-stack",
"path-to-regexp": "^1.5.0",
"reduce-flatten": "^1.0.0",
"stream-log-stats": "^1.1.3",
"test-value": "^2.0.0",
"local-web-server-default-stack": "github:local-web-server/default-stack",
"reduce-flatten": "^1.0.1",
"typical": "^2.4.2", "typical": "^2.4.2",
"walk-back": "^2.0.1" "walk-back": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"jsdoc-to-markdown": "^1.3.6", "jsdoc-to-markdown": "^1.3.6",
"koa-cache-control": "^1.0.0", "koa-cache-control": "^1.0.0",
"koa-livereload": "^0.1.23",
"koa-livereload": "~0.2.0",
"req-then": "~0.2.4", "req-then": "~0.2.4",
"tape": "^4.5.1"
"tape": "^4.6.0"
} }
} }
Loading…
Cancel
Save