Browse Source

extend examples

master
Lloyd Brookes 9 years ago
parent
commit
6298f693cd
  1. 3
      extend/cache-control/.local-web-server.json
  2. 9
      extend/cache-control/server.js
  3. 0
      extend/live-reload-optional/index.html
  4. 19
      extend/live-reload-optional/server.js
  5. 10
      extend/live-reload/index.html
  6. 2
      extend/live-reload/server.js
  7. 2
      lib/cli-data.js
  8. 4
      lib/local-web-server.js

3
extend/cache-control/.local-web-server.json

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

9
extend/cache-control.js → extend/cache-control/server.js

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

0
extend/index.html → extend/live-reload-optional/index.html

19
extend/live-reload-optional/server.js

@ -0,0 +1,19 @@
'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()
.start()

10
extend/live-reload/index.html

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>live-reload demo</title>
</head>
<body>
<h1>Live reloaded attached</h1>
</body>
</html>

2
extend/live-reload.js → extend/live-reload/server.js

@ -1,5 +1,5 @@
'use strict' 'use strict'
const Cli = require('../')
const Cli = require('../../')
const liveReload = require('koa-livereload') const liveReload = require('koa-livereload')
const ws = new Cli() const ws = new Cli()

2
lib/cli-data.js

@ -38,7 +38,7 @@ function usage (middlewareDefinitions) {
{ {
header: 'Synopsis', header: 'Synopsis',
content: [ content: [
'$ ws [<server options>]',
'$ ws [--verbose] [<server options>] [<middleware options>]',
'$ ws --config', '$ ws --config',
'$ ws --help' '$ ws --help'
] ]

4
lib/local-web-server.js

@ -146,7 +146,3 @@ function validateOptions (options) {
} }
module.exports = LocalWebServer module.exports = LocalWebServer
process.on('unhandledRejection', (reason, p) => {
console.error('unhandledRejection', reason, p)
})
Loading…
Cancel
Save