@untool/express
Advanced tools
Comparing version 0.4.3 to 0.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.5.0"></a> | ||
# [0.5.0](https://github.com/untool/untool/compare/v0.4.3...v0.5.0) (2018-05-07) | ||
### Features | ||
* **express:** add 404 middleware to renderer ([04aa35b](https://github.com/untool/untool/commit/04aa35b)) | ||
<a name="0.4.3"></a> | ||
@@ -8,0 +19,0 @@ ## [0.4.3](https://github.com/untool/untool/compare/v0.4.2...v0.4.3) (2018-04-24) |
@@ -41,3 +41,3 @@ const { readFileSync: readFile } = require('fs'); | ||
module.exports = (app, config, inspectServer, logInfo, logError) => { | ||
module.exports = (app, config, inspect, logInfo, logError) => { | ||
const { ip = '0.0.0.0', port, basePath, https } = config; | ||
@@ -51,3 +51,3 @@ const server = createServer(app, https); | ||
} else { | ||
inspectServer(server); | ||
inspect(server); | ||
logInfo( | ||
@@ -54,0 +54,0 @@ 'server listening at %s', |
@@ -7,5 +7,5 @@ const express = require('express'); | ||
module.exports = (options, config, initializeServer, finalizeServer) => { | ||
module.exports = (method, options, config, initialize, finalize) => { | ||
const app = express(); | ||
initializeServer(app, 'serve'); | ||
initialize(app, method); | ||
app.use(rewriteMiddleware(options, config)); | ||
@@ -17,3 +17,6 @@ app.use(helmet()); | ||
setHeaders: function(res, filePath) { | ||
if (res.locals.noCache || mime.getType(filePath) === 'text/html') { | ||
if ( | ||
(res && res.locals && res.locals.noCache) || | ||
mime.getType(filePath) === 'text/html' | ||
) { | ||
helmet.noCache()(null, res, function() {}); | ||
@@ -26,4 +29,4 @@ } | ||
app.use(helmet.noCache()); | ||
finalizeServer(app, 'serve'); | ||
finalize(app, method); | ||
return app; | ||
}; |
@@ -6,6 +6,7 @@ const EventEmitter = require('events'); | ||
module.exports = (options, config, initializeServer, finalizeServer) => { | ||
module.exports = (method, options, config, initialize, finalize) => { | ||
const app = new Router(); | ||
initializeServer(app, 'static'); | ||
finalizeServer(app, 'static'); | ||
initialize(app, method); | ||
finalize(app, method); | ||
app.use((req, res) => res.status(404).end()); | ||
return options => { | ||
@@ -12,0 +13,0 @@ if (typeof options === 'string') { |
@@ -1,2 +0,5 @@ | ||
const { sync: { sequence } } = require('mixinable'); | ||
const { | ||
sync: { sequence, override: overrideSync }, | ||
async: { override: overrideAsync }, | ||
} = require('mixinable'); | ||
@@ -8,31 +11,29 @@ const { Mixin } = require('@untool/core'); | ||
class ExpressMixin extends Mixin { | ||
constructor(...args) { | ||
super(...args); | ||
this.options = {}; | ||
create(method) { | ||
const create = require(method === 'static' | ||
? './lib/static' | ||
: './lib/serve'); | ||
const { options, config, initializeServer, finalizeServer } = this; | ||
return create(method, options, config, initializeServer, finalizeServer); | ||
} | ||
create(method, options) { | ||
const create = require(`./lib/${method}`); | ||
const { config, initializeServer, finalizeServer } = this; | ||
return create(options, config, initializeServer, finalizeServer); | ||
} | ||
run(method, options) { | ||
run(method) { | ||
const run = require('./lib/run'); | ||
const { config, inspectServer, logInfo, logError } = this; | ||
const app = this.create(method, options); | ||
const app = this.create(method); | ||
return run(app, config, inspectServer, logInfo, logError); | ||
} | ||
runServer(options) { | ||
return this.run('serve', options); | ||
runServer() { | ||
return this.run('serve'); | ||
} | ||
runDevServer(options) { | ||
return this.run('develop', options); | ||
runDevServer() { | ||
return this.run('develop'); | ||
} | ||
createServer(options) { | ||
return this.create('serve', options); | ||
createServer() { | ||
return this.create('serve'); | ||
} | ||
createDevServer(options) { | ||
return this.create('develop', options); | ||
createDevServer() { | ||
return this.create('develop'); | ||
} | ||
createRenderer(options) { | ||
return this.create('static', options); | ||
createRenderer() { | ||
return this.create('static'); | ||
} | ||
@@ -55,7 +56,2 @@ renderLocations() { | ||
} | ||
getAssetPath(filePath) { | ||
const { config: { assetPath } } = this; | ||
const { resolveRelative } = uri; | ||
return resolveRelative(assetPath, filePath); | ||
} | ||
initializeServer(app, mode) { | ||
@@ -77,3 +73,3 @@ const { compress } = this.config; | ||
alias: 'p', | ||
default: true, | ||
default: false, | ||
describe: 'Enable production mode', | ||
@@ -95,5 +91,8 @@ type: 'boolean', | ||
}, | ||
handler: argv => this.runServer(argv), | ||
handler: () => this.runServer(), | ||
}); | ||
} | ||
handleArguments(argv) { | ||
this.options = { ...this.options, ...argv }; | ||
} | ||
} | ||
@@ -105,4 +104,7 @@ | ||
inspectServer: sequence, | ||
runServer: overrideSync, | ||
runDevServer: overrideSync, | ||
renderLocations: overrideAsync, | ||
}; | ||
module.exports = ExpressMixin; |
{ | ||
"name": "@untool/express", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "untool express mixin", | ||
@@ -26,3 +26,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@untool/core": "^0.4.3", | ||
"@untool/core": "^0.5.0", | ||
"@untool/yargs": "^0.5.0", | ||
"compression": "^1.7.2", | ||
@@ -29,0 +30,0 @@ "directory-index": "^0.1.0", |
@@ -77,2 +77,14 @@ # `@untool/express` | ||
### `runServer(options)` ([override](https://github.com/untool/mixinable/blob/master/README.md#defineoverride)) | ||
If you want to programmatically start a production ready Express server set up using `@untool/express`' [config](https://github.com/untool/untool/blob/master/packages/express/README.md#settings), you can use this utility mixin method that accepts the same options as the CLI [`serve`](https://github.com/untool/untool/blob/master/packages/express/README.md#arguments) method. | ||
### `runDevServer(options)` ([override](https://github.com/untool/mixinable/blob/master/README.md#defineoverride)) | ||
To start a development mode Express server programmatically, you can use this utility mixin method. It uses a [`static`](https://github.com/untool/untool/blob/master/packages/express/README.md#-s----static) option and `@untool/express`' [settings](https://github.com/untool/untool/blob/master/packages/express/README.md#settings) for its configuration. | ||
### `renderLocations()` ([override](https://github.com/untool/mixinable/blob/master/README.md#defineoverride)) | ||
With this method you can render HTML pages for all configured [`locations`](https://github.com/untool/untool/blob/master/packages/express/README.md#locations) using a simulated Express server configured using `@untool/express`' [settings](https://github.com/untool/untool/blob/master/packages/express/README.md#settings). This method returns a `Promise` resolving to a hash containing the rendered paths. | ||
## Settings | ||
@@ -79,0 +91,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
23396
218
10
12
297
+ Added@untool/yargs@^0.5.0
+ Added@untool/core@0.5.0(transitive)
+ Added@untool/yargs@0.5.0(transitive)
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedcaller-callsite@2.0.0(transitive)
+ Addedcaller-path@2.0.0(transitive)
+ Addedcallsites@2.0.0(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcosmiconfig@5.2.1(transitive)
+ Addedcross-spawn@6.0.6(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedimport-fresh@2.0.0(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedresolve-from@3.0.0(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@11.1.1(transitive)
+ Addedyargs-parser@9.0.2(transitive)
- Removed@untool/core@0.4.3(transitive)
- Removedcosmiconfig@4.0.0(transitive)
- Removedrequire-from-string@2.0.2(transitive)
Updated@untool/core@^0.5.0