Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

frozen-express

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frozen-express - npm Package Compare versions

Comparing version 0.2.0 to 0.3.1

.eslintrc

28

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc