Lloyd Brookes
8 years ago
10 changed files with 15 additions and 535 deletions
-
4.travis.yml
-
2LICENSE
-
2README.md
-
3bin/cli.js
-
87lib/cli-data.js
-
47lib/feature.js
-
332lib/local-web-server.js
-
26package.json
-
20ssl/127.0.0.1.crt
-
27ssl/127.0.0.1.key
@ -1,5 +1,3 @@ |
|||
language: node_js |
|||
node_js: |
|||
- 4 |
|||
- 5 |
|||
- 6 |
|||
- 7 |
@ -1,4 +1,5 @@ |
|||
#!/usr/bin/env node
|
|||
'use strict' |
|||
const LocalWebServer = require('../') |
|||
new LocalWebServer() |
|||
const localWebServer = new LocalWebServer() |
|||
localWebServer.start() |
@ -1,87 +0,0 @@ |
|||
exports.optionDefinitions = [ |
|||
{ |
|||
name: 'port', alias: 'p', type: Number, defaultOption: true, |
|||
description: 'Web server port.', group: 'server' |
|||
}, |
|||
{ |
|||
name: 'stack', type: String, multiple: true, |
|||
description: 'Feature stack.', group: 'server' |
|||
}, |
|||
{ |
|||
name: 'key', type: String, typeLabel: '[underline]{file}', group: 'server', |
|||
description: 'SSL key. Supply along with --cert to launch a https server.' |
|||
}, |
|||
{ |
|||
name: 'cert', type: String, typeLabel: '[underline]{file}', group: 'server', |
|||
description: 'SSL cert. Supply along with --key to launch a https server.' |
|||
}, |
|||
{ |
|||
name: 'https', type: Boolean, group: 'server', |
|||
description: 'Enable HTTPS using a built-in key and cert, registered to the domain 127.0.0.1.' |
|||
}, |
|||
{ |
|||
name: 'help', alias: 'h', type: Boolean, |
|||
description: 'Print these usage instructions.', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'view', type: String, |
|||
description: 'Custom view', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'config', type: Boolean, |
|||
description: 'Print the stored config.', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'config-file', type: String, |
|||
description: 'Config file to use', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'verbose', type: Boolean, alias: 'v', |
|||
description: 'Verbose output.', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'debug', type: Boolean, |
|||
description: 'Very verbose output, intended for debugging.', group: 'misc' |
|||
}, |
|||
{ |
|||
name: 'version', type: Boolean, |
|||
description: 'Print the version number.', group: 'misc' |
|||
} |
|||
] |
|||
|
|||
function usage (middlewareDefinitions) { |
|||
return [ |
|||
{ |
|||
header: 'local-web-server', |
|||
content: 'A simple web-server for productive front-end development.' |
|||
}, |
|||
{ |
|||
header: 'Synopsis', |
|||
content: [ |
|||
'$ ws [--verbose] [<server options>] [<middleware options>]', |
|||
'$ ws --config', |
|||
'$ ws --help' |
|||
] |
|||
}, |
|||
{ |
|||
header: 'Server', |
|||
optionList: exports.optionDefinitions, |
|||
group: 'server' |
|||
}, |
|||
{ |
|||
header: 'Middleware', |
|||
optionList: middlewareDefinitions, |
|||
group: 'middleware' |
|||
}, |
|||
{ |
|||
header: 'Misc', |
|||
optionList: exports.optionDefinitions, |
|||
group: 'misc' |
|||
}, |
|||
{ |
|||
content: 'Project home: [underline]{https://github.com/75lb/local-web-server}' |
|||
} |
|||
] |
|||
} |
|||
|
|||
exports.usage = usage |
@ -1,47 +0,0 @@ |
|||
'use strict' |
|||
|
|||
/** |
|||
* Feature interface. |
|||
*/ |
|||
class Feature { |
|||
/** |
|||
* localWebServer instance passed to constructor in case feature needs access to http server instance. |
|||
*/ |
|||
constructor (localWebServer) {} |
|||
|
|||
/** |
|||
* Return one or more options definitions to collect command-line input |
|||
* @returns {OptionDefinition|OptionDefinition[]} |
|||
*/ |
|||
optionDefinitions () {} |
|||
|
|||
/** |
|||
* Return one of more middleware functions with three args (req, res and next). Can be created by express, Koa or hand-rolled. |
|||
*/ |
|||
middleware (options) {} |
|||
|
|||
expandStack () { |
|||
const flatten = require('reduce-flatten') |
|||
|
|||
if (this.stack) { |
|||
const featureStack = this.stack() |
|||
.map(Feature => new Feature()) |
|||
|
|||
this.optionDefinitions = function () { |
|||
return featureStack |
|||
.map(feature => feature.optionDefinitions && feature.optionDefinitions()) |
|||
.filter(definitions => definitions) |
|||
.reduce(flatten, []) |
|||
} |
|||
this.middleware = function (options, view) { |
|||
return featureStack |
|||
.map(feature => feature.middleware(options, view)) |
|||
.reduce(flatten, []) |
|||
.filter(mw => mw) |
|||
} |
|||
} |
|||
return this |
|||
} |
|||
} |
|||
|
|||
module.exports = Feature |
@ -1,20 +0,0 @@ |
|||
-----BEGIN CERTIFICATE----- |
|||
MIIDLjCCAhYCCQC3MW7xH6DDyTANBgkqhkiG9w0BAQUFADBZMQswCQYDVQQGEwJH |
|||
QjETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 |
|||
cyBQdHkgTHRkMRIwEAYDVQQDEwkxMjcuMC4wLjEwHhcNMTYwMzEwMTAzMTMwWhcN |
|||
MTcwMzEwMTAzMTMwWjBZMQswCQYDVQQGEwJHQjETMBEGA1UECBMKU29tZS1TdGF0 |
|||
ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRIwEAYDVQQDEwkx |
|||
MjcuMC4wLjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIWz+H5P3P |
|||
5/Uixviwbj88y112TBCCdhPizqVb8f7EgTgeIA0Jpqe2+RR9siawwUAX9nqRUB1g |
|||
vgLZE4NZS+5ICN3JqkC4EysDS6VtIVf2OAuem3kdKaHSLl4JabsmBprgf2Dtze0i |
|||
eX5+Pur5Pi2BEAYNCUKzC4OuVaP//3jNWD/Xp6eHBbC76L03EIGPxytYf5wkITbY |
|||
wCjIVQw0Mq+WsV9eJRuLT4bnoeefCK+zPeTEQ6o+3SFkTkhqfsTF83sHvgcy1T4u |
|||
7f+GZ9TYiaUi/1OVvfUg2FdGDAlKtVVH/t+pAg0M2hGr7vTClSVOg/qiY3ktEaYW |
|||
FvcxJa65DyQNAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBAFwrxsqXwA6BTFTvRYi1 |
|||
s4tqos8loaZxE4eug96mL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OqH7BINia/qud |
|||
BLLJwHamzToWH7NTSWqrM4X9I7mI3zcMfOGeH9yZEFhB3cVu63V4yHfnGGqEiUOk |
|||
21fA+iLBAoGBAPXwZskl+nM0Z7yadaOOCqjRMdvPIgHOvQvjKtQJ/E7I4sH3ZBfO |
|||
4YPU0pErV4rbOyv6TZcUQwmcHmepK5wcHjj52+vgDQMr+K1wjRai8WdapKgXi39n |
|||
5IgPD0y5Hgi7qUJI6w67ybkawgknL8hm6TwtxfbKtVoJ5BVgS1UmFMYRAoGBANCN |
|||
e3X685aGqsyuCVU3bXnZVGyromiCDQge3NGuUFqaSCA0uK9/Q4HuStktH7LiRoZo |
|||
UwBmdnF0Wa4hMcjBBONv1bc8S43CdoJC3LR6DdFL8j4YarUSXnTFRo+MnKIbNwQh |
|||
378E1ws+dsOGrJ+IIqQJHfzsnG+vvb9PUleXgtI9AoGAFOBKKUri/oJ1R8oosDBv |
|||
cTMIs2rarSKaY3bt/L+4PgvJS8OvKGI0PFeFZDM0pCHF3Q7LJUbgBeHNpujyPbcZ |
|||
TabP5y7Gi/1gh4BlSYWdTjOghHAzNCZifLYii1WvWfhr/qdn5IFGN0MxM0uzP6SU |
|||
qboM8sz0JedvB+17l4e6/bECgYBYI0MHJGyns/ghEngtRISG13tfhdXYVwYM5YYr |
|||
M4EQGV3cBov610z/b2bAi9p2rjxh91sEs0jhP+vatHqmvjRDrnLiwp+npISTHpDJ |
|||
0T9fsboJ1iXaqo2yyeC9MA7OT7QbkflOcEw1m0tz7MmtjkodiyDaUGD4rowBexNw |
|||
oz6NfQKBgQCbhTO6MNmdeQrJn/ojR6HipypKqpVXqqqraAgU5BapaH0ZZwXkXDAM |
|||
36ldQviX8UnPNFqHj7jzVSNyWsgmKHnXFmdTEBYTd+0b+WEyn9FR/8kBlxHFR7Nc |
|||
AcAF7XF79pkJM31e6GCwFymYPbFJEL4TkWSOnPkypGY6IXHp57bKzA== |
|||
-----END RSA PRIVATE KEY----- |
Write
Preview
Loading…
Cancel
Save
Reference in new issue