Skip to content

Instantly share code, notes, and snippets.

@dwaligora
Last active August 29, 2015 14:06
Show Gist options
  • Save dwaligora/de92f1ee9375f8b809fe to your computer and use it in GitHub Desktop.
Save dwaligora/de92f1ee9375f8b809fe to your computer and use it in GitHub Desktop.
router.user require callback function
'use strict';
module.exports = function(app) {
/*
* resources
*/
app.use(require('./zip')(app));
};
vagrant@zipper:/var/www/zipper$ node runserver.js
/var/www/zipper/node_modules/express/lib/router/index.js:416
throw new TypeError('Router.use() requires callback function');
^
TypeError: Router.use() requires callback function
at Function.use (/var/www/zipper/node_modules/express/lib/router/index.js:416:11)
at Function.use (/var/www/zipper/node_modules/express/lib/application.js:193:14)
at module.exports (/var/www/zipper/kernel/api/v1/index.js:7:9)
at module.exports (/var/www/zipper/kernel/api/index.js:41:41)
at Object.<anonymous> (/var/www/zipper/app.js:9:32)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
'use strict';
var request = require('request'),
async = require('async'),
util = require('util'),
fs = require('fs'),
https = require('https'),
http = require('http'),
hash = require('object-hash'),
pkgcloud = require('pkgcloud'),
config = require('../../../config'),
session = require('../../../lib/session'),
archiver = require('archiver'),
formatterManager = require('../../../lib/formatter'),
settingsManager = require('../../../lib/settings'),
zipManager = require('../../../lib/zip/manager');
module.exports = function(app) {
/**
* POST /zip - preparing archive token for easy downloading from browser (/GET method)
*/
app.post(
'/zip',
require('../../../middleware/validator/zip').Create,
require('../../../middleware/validator/response/api'),
postZipHandler,
require('../../../middleware/http/response/json')
);
};
/**
* @param {Request} req
* @param {Response} res
* @param {Function} next
*/
function postZipHandler(req, res, next) {
zipManager.switchStorageDb(10);
res.locals.archiveHashString = hash(req.body);
// store data & set expiration time
zipManager.saveArchiveData(
formatterManager.get('redis.key').format([
session.getClient(),
session.getProvider(),
'archive',
res.locals.archiveHashString
]),
req.body,
60 * 60 * 24 * 30
);
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment