extend examples
This commit is contained in:
3
extend/cache-control/.local-web-server.json
Normal file
3
extend/cache-control/.local-web-server.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"maxage": 2000
|
||||||
|
}
|
@ -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 })
|
||||||
}
|
}
|
19
extend/live-reload-optional/server.js
Normal file
19
extend/live-reload-optional/server.js
Normal file
@ -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
Normal file
10
extend/live-reload/index.html
Normal file
@ -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>
|
@ -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()
|
@ -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'
|
||||||
]
|
]
|
||||||
|
@ -146,7 +146,3 @@ function validateOptions (options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = LocalWebServer
|
module.exports = LocalWebServer
|
||||||
|
|
||||||
process.on('unhandledRejection', (reason, p) => {
|
|
||||||
console.error('unhandledRejection', reason, p)
|
|
||||||
})
|
|
||||||
|
Reference in New Issue
Block a user