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.1.0 to 0.2.0

src/errors.js

14

package.json
{
"name": "frozen-express",
"version": "0.1.0",
"version": "0.2.0",
"description": "Freeze an Express.js application into a set of static files",
"main": "src/frozen.js",
"scripts": {
"test": "mocha test && jshint src"
"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"
},

@@ -23,2 +26,3 @@ "repository": {

"dependencies": {
"error-factory": "0.0.15",
"mime": "^1.2.11",

@@ -31,4 +35,6 @@ "promise": "^5.0.0",

"devDependencies": {
"better-assert": "^1.0.0",
"express": "^4.4.2",
"coveralls": "^2.10.0",
"express": "^4",
"express3": "*",
"istanbul": "^0.2.11",
"jshint": "^2.5.1",

@@ -35,0 +41,0 @@ "mocha": "^1.20.1"

@@ -5,4 +5,7 @@ # Frozen Express

Express 4 and Express 3 applications are supported.
[![Build Status](https://travis-ci.org/denis-sokolov/frozen-express.svg?branch=master)](https://travis-ci.org/denis-sokolov/frozen-express)
[![Code Climate](http://img.shields.io/codeclimate/github/denis-sokolov/frozen-express.svg)](https://codeclimate.com/github/denis-sokolov/frozen-express)
[![Coverage Status](https://img.shields.io/coveralls/denis-sokolov/frozen-express.svg)](https://coveralls.io/r/denis-sokolov/frozen-express?branch=master)
[![Dependency Status](https://gemnasium.com/denis-sokolov/frozen-express.svg)](https://gemnasium.com/denis-sokolov/frozen-express)

@@ -15,9 +18,3 @@

var stream = frozen(app, {
routes: [
'/',
'/about',
'/contact'
]
});
var stream = frozen(app);
```

@@ -31,9 +28,17 @@

frozen(app, {
routes: [
'/'
]
}).pipe(gulp.dest('./dist'));
frozen(app).pipe(gulp.dest('./dist'));
```
You can also include it in your Gulp workflow and perform more tasks with files.
### Options
Frozen Express supports a number of options:
```javascript
var stream = frozen(app, {
// A list of URLs to freeze
// By default Frozen will try to detect the URLs itself
urls: ['/', '/about', '/contact']
});
```

@@ -9,6 +9,8 @@ 'use strict';

var errors = require('./errors.js');
var routes = require('./lib/routes.js');
module.exports = function(app, options) {
options = options || {};
options.routes = options.routes || [];
options.urls = options.urls || routes.detectUrls(app);

@@ -18,10 +20,21 @@ var pipe = through.obj();

options.routes.forEach(function(route){
app.use(function(req){
pipe.emit('error', new errors.ConfigurationError(
'URL '+req.originalUrl+' does not have a handler.'
));
});
options.urls.forEach(function(url){
promises.push(new Promise(function(resolve){
supertest(app).get(route).end(function(err, res){
if (/\/$/.exec(route))
route += 'index';
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() + route + '.' + mime.extension(res.get('content-type')),
path: process.cwd() + url,
base: process.cwd()

@@ -40,1 +53,3 @@ }));

};
module.exports.errors = errors;
'use strict';
var express = require('express');
var frozen = require('..');
var util = require('./util.js');
var test = util.test(frozen, express);
var test = util.test(frozen);
/* global it */
it('should return a js file', function(done){
test(done)
util.it('should return a js file', function(express, done){
test(express, done)
.route('/scripts', 'scripts.js', '2+2', function(res){

@@ -15,0 +11,0 @@ res.contentType('application/javascript');

'use strict';
var express = require('express');
var frozen = require('..');
var util = require('./util.js');
var test = util.test(frozen, express);
var test = util.test(frozen);
/* global it */
it('should return a single static file', function(done){
test(done)
util.it('should return a single static file', function(express, done){
test(express, done)
.route('/hello', 'hello.html', 'Hello world!')

@@ -18,4 +14,4 @@ .run();

it('should return two static files', function(done){
test(done)
util.it('should return two static files', function(express, done){
test(express, done)
.route('/hello', 'hello.html', 'Hello world!')

@@ -26,6 +22,19 @@ .route('/goodbye', 'goodbye.html', 'Goodbye!')

it('should handle root index path', function(done){
test(done)
util.it('should return static files only for given routes', function(express, done){
test(express, done)
.route('/hello', 'hello.html', 'Hello world!')
.route('/goodbye', 'goodbye.html', 'Goodbye!')
.results({urls:['/hello']}).then(function(results){
if (results.length > 1) {
done(new Error('Generated too many results'));
} else {
done();
}
});
});
util.it('should handle root index path', function(express, done){
test(express, done)
.route('/', 'index.html', 'Hello world!')
.run();
});
'use strict';
var express = require('express');
var express3 = require('express3');
var Promise = require('promise');

@@ -17,12 +19,14 @@ var through = require('through2');

lib.makeapp = function(express, routes) {
var app = express();
routes.forEach(function(route){
app.get(route.url, function(req, res){
if (route.handler) {
route.handler(res);
}
res.send(route.contents);
return new Promise(function(resolve){
var app = express();
routes.forEach(function(route){
app.get(route.url, function(req, res){
if (route.handler) {
route.handler(res);
}
res.send(route.contents);
});
});
resolve(app);
});
return app;
};

@@ -36,4 +40,5 @@

lib.pipeContents = function(pipe){
return new Promise(function(resolve){
return new Promise(function(resolve, reject){
var result = [];
pipe.on('error', function(err){ reject(err); });
pipe.pipe(through.obj(function(data, enc, next){

@@ -48,4 +53,20 @@ result.push(data);

api.test = function(frozen, express){
return function(done){
/**
* Run a single test with multiple Express application versions
* @param name
* @param {Function} callback
*/
api.it = function(name, callback){
/* global it */
it('[express4] '+name, function(done){
callback(express, done);
});
it('[express3] '+name, function(done){
callback(express3, done);
});
};
api.test = function(frozen){
return function(express, done){
var routes = [];

@@ -61,10 +82,25 @@ var test = {};

test.run = function(){
var app = lib.makeapp(express, routes);
lib.pipeContents(frozen(app, {
routes: routes.map(function(route){
test.results = function(options){
options = options || {};
if (options.urls !== null) {
options.urls = options.urls || routes.map(function(route){
return route.url;
})
})).then(function(results){
var missing = routes.filter(function(route){
});
}
return lib.makeapp(express, routes).then(function(app){
return lib.pipeContents(frozen(app, {
urls: options.urls
}));
});
};
test.run = function(options){
options = options || {};
options.checkRoutes = options.checkRoutes || routes;
return test.results({
urls: options.urls
}).then(function(results){
var missing = options.checkRoutes.filter(function(route){
return !results.some(function(attempt){

@@ -71,0 +107,0 @@ if (attempt.relative !== route.path) {

Sorry, the diff of this file is not supported yet

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