frozen-express
Advanced tools
Comparing version 0.2.0 to 0.3.1
{ | ||
"name": "frozen-express", | ||
"version": "0.2.0", | ||
"version": "0.3.1", | ||
"description": "Freeze an Express.js application into a set of static files", | ||
"main": "src/frozen.js", | ||
"scripts": { | ||
"report-coverage": "istanbul cover --report lcovonly _mocha test && coveralls < coverage/lcov.info", | ||
"coverage": "istanbul cover _mocha test", | ||
"lint": "jshint src", | ||
"test": "mocha test && npm run lint" | ||
"report-coverage": "istanbul cover --report lcovonly _mocha test test/functional && coveralls < coverage/lcov.info", | ||
"coverage": "istanbul cover _mocha test test/functional", | ||
"lint": "jshint src && eslint src", | ||
"test": "mocha test test/functional && npm run lint", | ||
"test-server-run": "mocha ./test/server/run.js" | ||
}, | ||
"bin": "src/bin.js", | ||
"repository": { | ||
@@ -26,17 +28,21 @@ "type": "git", | ||
"dependencies": { | ||
"error-factory": "0.0.15", | ||
"error-factory": "^0.1.0", | ||
"gulp": "^3.8.1", | ||
"mime": "^1.2.11", | ||
"promise": "^5.0.0", | ||
"supertest": "^0.13.0", | ||
"promise": "^6.1.0", | ||
"supertest": "^0.15.0", | ||
"through2": "^1.0.0", | ||
"vinyl": "^0.2.3" | ||
"vinyl": "^0.4.6" | ||
}, | ||
"devDependencies": { | ||
"argparse": "^0.1.15", | ||
"coveralls": "^2.10.0", | ||
"eslint": "^0.10.1", | ||
"express": "^4", | ||
"express3": "*", | ||
"istanbul": "^0.2.11", | ||
"istanbul": "^0.3.0", | ||
"jshint": "^2.5.1", | ||
"mocha": "^1.20.1" | ||
"mocha": "^1.20.1", | ||
"request": "^2.36.0" | ||
} | ||
} |
@@ -10,2 +10,4 @@ # Frozen Express | ||
[![Coverage Status](https://img.shields.io/coveralls/denis-sokolov/frozen-express.svg)](https://coveralls.io/r/denis-sokolov/frozen-express?branch=master) | ||
[![bitHound Score](https://app.bithound.io/denis-sokolov/frozen-express/badges/score.svg)](http://app.bithound.io/denis-sokolov/frozen-express) | ||
[![Codacy Badge](https://www.codacy.com/project/badge/b0d4b7efff974dbba490fb12861ef11c)](https://www.codacy.com/app/denis_2849/frozen-express) | ||
[![Dependency Status](https://gemnasium.com/denis-sokolov/frozen-express.svg)](https://gemnasium.com/denis-sokolov/frozen-express) | ||
@@ -15,2 +17,18 @@ | ||
You can use Frozen Express as a command line tool or access it programatically. | ||
### Command line | ||
Once you install Frozen Express (`npm install -g frozen-express`), you can use it as follows: | ||
```bash | ||
frozen-express app.js dist | ||
``` | ||
Here the `app.js` is your module that exports the application, and `dist` is the directory to put the generated files. | ||
Most Frozen Express options are available as command line options, use `frozen-express -h` to see their usage. | ||
### API | ||
```javascript | ||
@@ -39,2 +57,18 @@ var frozen = require('frozen-express'); | ||
var stream = frozen(app, { | ||
// Apache specific settings | ||
// Use only if server is set to apache | ||
apache: { | ||
// Any custom .htaccess content to append to the generated file | ||
extraHtaccess: '', | ||
} | ||
// Base URL for the website relative to domain root | ||
// Required if server is set to apache | ||
// Use a single slash if the website will be hosted in the domain root | ||
base: '/subdir/', | ||
// Add control files for serving the application with a particular server | ||
// Valid options: 'apache' | ||
server: false, | ||
// A list of URLs to freeze | ||
@@ -41,0 +75,0 @@ // By default Frozen will try to detect the URLs itself |
@@ -13,5 +13,5 @@ /** | ||
var err = function(name) { | ||
return factory('FrozenExpress.'+name+'Error'); | ||
return factory('FrozenExpress.' + name + 'Error'); | ||
}; | ||
module.exports.ConfigurationError = err('Configuration'); |
'use strict'; | ||
var File = require('vinyl'); | ||
var mime = require('mime'); | ||
var Promise = require('promise'); | ||
var supertest = require('supertest'); | ||
var through = require('through2'); | ||
var errors = require('./errors.js'); | ||
var servers = { | ||
apache: require('./servers/apache.js') | ||
}; | ||
var routes = require('./lib/routes.js'); | ||
var urlToFile = require('./lib/urlToFile.js'); | ||
var unhandled = 'FROZEN_UNHANDLED'; | ||
module.exports = function(app, options) { | ||
options = options || {}; | ||
if (options.server && !(options.server in servers)) | ||
throw new errors.ConfigurationError('Invalid server setting'); | ||
options.urls = options.urls || routes.detectUrls(app); | ||
var pipe = through.obj(); | ||
var addFile = function(f) { | ||
var path = f.path; | ||
if (path.substr(0, 1) !== '/') { | ||
path = '/' + path; | ||
} | ||
pipe.push(new File({ | ||
contents: new Buffer(f.contents), | ||
path: process.cwd() + path, | ||
base: process.cwd() | ||
})); | ||
}; | ||
var promises = []; | ||
app.use(function(req){ | ||
pipe.emit('error', new errors.ConfigurationError( | ||
'URL '+req.originalUrl+' does not have a handler.' | ||
)); | ||
// Express does not seem to provide API to unregister handlers | ||
// Work around that with done + next | ||
var done = false; | ||
app.use(function(req, res, next){ | ||
if (done) return next(); | ||
res.send(unhandled); | ||
}); | ||
options.urls.forEach(function(url){ | ||
promises.push(new Promise(function(resolve){ | ||
supertest(app).get(url).end(function(err, res){ | ||
if (/\/$/.exec(url)) | ||
url += 'index'; | ||
var correctExt = mime.extension(res.get('content-type')); | ||
if (correctExt !== 'bin' && mime.extension(mime.lookup(url)) !== correctExt) | ||
url += '.' + correctExt; | ||
pipe.push(new File({ | ||
contents: new Buffer(res.text), | ||
path: process.cwd() + url, | ||
base: process.cwd() | ||
})); | ||
resolve(); | ||
}); | ||
promises.push(urlToFile(app, url).then(function(f){ | ||
if (f.contents === unhandled) | ||
return Promise.reject(new errors.ConfigurationError( | ||
'URL ' + url + ' does not have a handler.' | ||
)); | ||
addFile(f); | ||
})); | ||
}); | ||
if (options.server) { | ||
promises.push(servers[options.server]({ | ||
addFile: addFile, | ||
base: options.base, | ||
options: options[options.server] || {} | ||
})); | ||
promises.push(urlToFile(app, '/.frozen_express_404', { | ||
expectedStatus: [404, 405] | ||
}).then(function(f){ | ||
addFile(f); | ||
}).catch(function(){ return; })); | ||
} | ||
Promise.all(promises).then(function(){ | ||
pipe.end(); | ||
done = true; | ||
}).catch(function(err){ | ||
done = true; | ||
pipe.emit('error', err); | ||
}); | ||
@@ -48,0 +76,0 @@ |
@@ -16,3 +16,3 @@ 'use strict'; | ||
* Warning! | ||
* This function access private API for Express 4 | ||
* This function accesses private API for Express 4 | ||
*/ | ||
@@ -19,0 +19,0 @@ var detectExpress4Urls = function(app){ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24131
26
633
76
7
9
4
+ Addedgulp@^3.8.1
+ Addedansi-gray@0.1.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedarchy@1.0.0(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-each@1.0.1(transitive)
+ Addedarray-slice@1.1.0(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbeeper@1.1.1(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedclone@0.2.01.0.4(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcookiejar@2.0.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddateformat@2.2.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addeddeprecated@0.0.1(transitive)
+ Addeddetect-file@1.0.0(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addedend-of-stream@0.1.5(transitive)
+ Addederror-factory@0.1.6(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedexpand-tilde@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfancy-log@1.3.3(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfind-index@0.1.1(transitive)
+ Addedfindup-sync@2.0.0(transitive)
+ Addedfined@1.2.0(transitive)
+ Addedfirst-chunk-stream@1.0.0(transitive)
+ Addedflagged-respawn@1.0.1(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@1.0.0(transitive)
+ Addedform-data@0.1.3(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgaze@0.5.2(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob@3.1.214.5.3(transitive)
+ Addedglob-stream@3.1.18(transitive)
+ Addedglob-watcher@0.0.6(transitive)
+ Addedglob2base@0.0.12(transitive)
+ Addedglobal-modules@1.0.0(transitive)
+ Addedglobal-prefix@1.0.2(transitive)
+ Addedglobule@0.1.0(transitive)
+ Addedglogg@1.0.2(transitive)
+ Addedgraceful-fs@1.2.33.0.12(transitive)
+ Addedgulp@3.9.1(transitive)
+ Addedgulp-util@3.0.8(transitive)
+ Addedgulplog@1.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-gulplog@0.1.0(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@1.0.2(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedis-absolute@1.0.0(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@3.1.0(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-relative@1.0.0(transitive)
+ Addedis-unc-path@1.0.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedliftoff@2.5.0(transitive)
+ Addedlodash@1.0.2(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basetostring@3.0.1(transitive)
+ Addedlodash._basevalues@3.0.0(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash._reescape@3.0.0(transitive)
+ Addedlodash._reevaluate@3.0.0(transitive)
+ Addedlodash._reinterpolate@3.0.0(transitive)
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash.escape@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.template@3.6.2(transitive)
+ Addedlodash.templatesettings@3.1.1(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedmake-iterator@1.0.1(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmethods@1.0.11.1.2(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedminimatch@0.2.142.0.10(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@2.0.0(transitive)
+ Addedmultipipe@0.1.2(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednatives@1.1.6(transitive)
+ Addedobject-assign@3.0.0(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.defaults@1.1.0(transitive)
+ Addedobject.map@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.3.3(transitive)
+ Addedorchestrator@0.3.8(transitive)
+ Addedordered-read-streams@0.1.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedparse-filepath@1.0.2(transitive)
+ Addedparse-node-version@1.0.1(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-root@0.1.1(transitive)
+ Addedpath-root-regex@0.1.2(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedpretty-hrtime@1.0.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpromise@6.1.0(transitive)
+ Addedqs@1.2.0(transitive)
+ Addedreadable-stream@1.0.342.3.8(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedresolve-dir@1.0.1(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedsemver@4.3.6(transitive)
+ Addedsequencify@0.0.7(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsparkles@1.0.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstream-consume@0.1.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-bom@1.0.0(transitive)
+ Addedsuperagent@0.21.0(transitive)
+ Addedsupertest@0.15.0(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedthrough2@0.6.52.0.5(transitive)
+ Addedtildify@1.2.0(transitive)
+ Addedtime-stamp@1.1.0(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunc-path-regex@0.1.2(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunique-stream@1.0.0(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addeduser-home@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedv8flags@2.1.1(transitive)
+ Addedvar-validator@0.0.3(transitive)
+ Addedvinyl@0.4.60.5.3(transitive)
+ Addedvinyl-fs@0.3.14(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedasync@0.2.10(transitive)
- Removedcookiejar@1.3.2(transitive)
- Removeddebug@0.7.4(transitive)
- Removederror-factory@0.0.15(transitive)
- Removedform-data@0.1.2(transitive)
- Removedmethods@0.0.11.0.0(transitive)
- Removedmime@1.2.5(transitive)
- Removedpromise@5.0.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedsuperagent@0.18.0(transitive)
- Removedsupertest@0.13.0(transitive)
- Removedvinyl@0.2.3(transitive)
Updatederror-factory@^0.1.0
Updatedpromise@^6.1.0
Updatedsupertest@^0.15.0
Updatedvinyl@^0.4.6