flatten modules, eager load sessions

This commit is contained in:
AJ ONeal 2015-03-29 03:28:41 +00:00
джерело a21c503b6e
коміт 7151868c62
3 змінених файлів з 164 додано та 128 видалено

@ -2,3 +2,76 @@
'use strict';
require('../walnut.js');
function eagerLoad() {
var PromiseA = require('bluebird').Promise
var promise = PromiseA.resolve();
[ 'passport'
, 'knex'
, 'bookshelf'
, 'express'
, 'request'
, 'sqlite3'
, 'body-parser'
, 'express-session'
, 'urlrouter'
, 'express-lazy'
, 'connect-send-error'
, 'underscore.string'
, 'bookshelf'
, 'secret-utils'
, 'connect-cors'
, 'uuid'
, 'connect-recase'
, 'passport-local'
, 'passport-strategy'
, 'passport-http'
, 'passport-http-bearer'
, 'escape-string-regexp'
, 'connect-query'
, 'recase'
].forEach(function (name, i) {
promise = promise.then(function () {
return new Promise(function (resolve, reject) {
setTimeout(function () {
require(name);
resolve();
}, 4);
});
});
});
[ function () {
return require('knex').initialize({
client: 'sqlite3'
, connection: {
filename : ':memory:'
}
});
}
, function (knex) {
require('bookshelf').initialize(knex);
}
, function () {
require('body-parser').json();
}
, function () {
require('body-parser').urlencoded();
}
].forEach(function (fn) {
promise = promise.then(function (thing) {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(fn(thing));
}, 4);
});
});
})
promise.then(function () {
console.log('Eager Loading Complete');
});
}
setTimeout(eagerLoad, 100);

@ -37,31 +37,96 @@
},
"homepage": "https://github.com/Daplie/walnut",
"dependencies": {
"bluebird": "^2.9.9",
"body-parser": "^1.12.0",
"check-ip-address": "^1.1.0",
"cli": "^0.6.5",
"compression": "^1.4.1",
"connect": "^3.3.4",
"connect-cors": "^0.5.6",
"connect-query": "^0.2.0",
"cookie-parser": "^1.3.4",
"errorhandler": "^1.3.4",
"escape-string-regexp": "^1.0.2",
"express": "^4.11.2",
"express-session": "^1.10.3",
"foreachasync": "^5.0.5",
"http-proxy": "^1.8.1",
"human-readable-ids": "^1.0.1",
"nat-pmp": "0.0.3",
"node-acme": "0.0.1",
"request": "^2.53.0",
"serve-favicon": "^2.2.0",
"serve-index": "^1.6.2",
"serve-static": "^1.9.1",
"ssl-root-cas": "^1.1.7",
"urlrouter": "^0.5.4",
"vhost": "^3.0.0",
"xml2js": "^0.4.5"
"accepts": "^1.2.5",
"bluebird": "2.x",
"body-parser": "1.x",
"btoa": "1.x",
"bytes": "^1.0.0",
"compression": "1.x",
"connect": "3.x",
"connect-cors": "0.5.x",
"connect-query": "0.2.x",
"connect-recase": "1.x",
"connect-send-error": "1.x",
"content-type": "^1.0.1",
"cookie": "^0.1.2",
"cookie-parser": "1.x",
"cookie-session": "1.x",
"cookie-signature": "^1.0.6",
"crc": "^3.2.1",
"debug": "^2.1.3",
"depd": "^1.0.0",
"destroy": "^1.0.3",
"dom-storage": "2.x",
"ee-first": "^1.1.0",
"errorhandler": "1.x",
"es6-promise": "2.x",
"escape-html": "^1.0.1",
"escape-string-regexp": "1.x",
"etag": "^1.5.1",
"express": "4.x",
"express-lazy": "1.x",
"express-session": "1.x",
"finalhandler": "^0.3.4",
"foreachasync": "5.x",
"fresh": "^0.2.4",
"human-readable-ids": "1.x",
"inherits": "^2.0.1",
"jarson": "1.x",
"json-storage": "2.x",
"lodash": "2.x",
"media-typer": "^0.3.0",
"methods": "^1.1.1",
"mime": "^1.3.4",
"mime-db": "^1.8.0",
"mime-types": "^2.0.10",
"ms": "^0.7.0",
"negotiator": "^0.5.1",
"node-pre-gyp": "^0.6.4",
"node-uuid": "1.x",
"nodemailer": "1.x",
"nodemailer-mailgun-transport": "1.x",
"oauth": "0.9.x",
"oauth2orize": "git://github.com/coolaj86/oauth2orize.git#v1.0.1+scope.1",
"on-finished": "^2.2.0",
"on-headers": "^1.0.0",
"parseurl": "^1.3.0",
"passport": "0.1.x",
"passport-facebook": "1.x",
"passport-google-plus": "0.2.x",
"passport-http": "0.2.x",
"passport-http-bearer": "1.x",
"passport-lds-connect": "1.x",
"passport-local": "1.x",
"passport-oauth": "1.x",
"passport-oauth1": "^1.0.1",
"passport-oauth2-client-password": "0.1.x",
"passport-oauth2-resource-owner-password": "1.x",
"passport-strategy": "^1.0.0",
"passport-twitter": "1.x",
"pkginfo": "^0.3.0",
"qs": "^2.4.1",
"range-parser": "^1.0.2",
"recase": "1.x",
"request": "2.44.0",
"scmp": "1.x",
"secret-utils": "1.x",
"semver": "^4.3.1",
"send": "^0.12.2",
"serve-favicon": "2.x",
"serve-static": "1.x",
"sqlite3": "3.x",
"ssl-root-cas": "1.x",
"twilio": "1.x",
"type-is": "^1.6.1",
"underscore.string": "2.x",
"urlrouter": "0.5.x",
"urlsafe-base64": "1.x",
"useragent": "2.x",
"utils-merge": "^1.0.0",
"uuid": "2.x",
"validator": "3.x",
"vary": "^1.0.0",
"vhost": "3.x"
}
}

102
serve.js

@ -1,102 +0,0 @@
#!/usr/bin/env node
'use strict';
var https = require('https')
, http = require('http')
, path = require('path')
, port = process.argv[2] || 65443
, insecurePort = process.argv[3] || 65080
, fs = require('fs')
, path = require('path')
, checkip = require('check-ip-address')
, server
, insecureServer
, options
, certsPath = path.join(__dirname, 'certs', 'server')
, caCertsPath = path.join(__dirname, 'certs', 'ca')
;
//
// SSL Certificates
//
options = {
key: fs.readFileSync(path.join(certsPath, 'my-server.key.pem'))
, ca: [ fs.readFileSync(path.join(caCertsPath, 'my-root-ca.crt.pem')) ]
, cert: fs.readFileSync(path.join(certsPath, 'my-server.crt.pem'))
, requestCert: false
, rejectUnauthorized: false
};
//
// Serve an Express App securely with HTTPS
//
server = https.createServer(options);
checkip.getExternalIp().then(function (ip) {
var host = ip || 'local.helloworld3000.com'
;
function listen(app) {
server.on('request', app);
server.listen(port, function () {
port = server.address().port;
console.log('Listening on https://127.0.0.1:' + port);
console.log('Listening on https://local.helloworld3000.com:' + port);
if (ip) {
console.log('Listening on https://' + ip + ':' + port);
}
});
}
var publicDir = path.join(__dirname, 'public');
var app = require('./app').create(server, host, port, publicDir);
listen(app);
});
//
// Redirect HTTP ot HTTPS
//
// This simply redirects from the current insecure location to the encrypted location
//
insecureServer = http.createServer();
insecureServer.on('request', function (req, res) {
var newLocation = 'https://'
+ req.headers.host.replace(/:\d+/, ':' + port) + req.url
;
var metaRedirect = ''
+ '<html>\n'
+ '<head>\n'
+ ' <style>* { background-color: white; color: white; text-decoration: none; }</style>\n'
+ ' <META http-equiv="refresh" content="0;URL=' + newLocation + '">\n'
+ '</head>\n'
+ '<body style="display: none;">\n'
+ ' <p>You requested an insecure resource. Please use this instead: \n'
+ ' <a href="' + newLocation + '">' + newLocation + '</a></p>\n'
+ '</body>\n'
+ '</html>\n'
;
// DO NOT HTTP REDIRECT
/*
res.setHeader('Location', newLocation);
res.statusCode = 302;
*/
// BAD NEWS BEARS
//
// When people are experimenting with the API and posting tutorials
// they'll use cURL and they'll forget to prefix with https://
// If we allow that, then many users will be sending private tokens
// and such with POSTs in clear text and, worse, it will work!
// To minimize this, we give browser users a mostly optimal experience,
// but people experimenting with the API get a message letting them know
// that they're doing it wrong and thus forces them to ensure they encrypt.
res.setHeader('Content-Type', 'text/html');
res.end(metaRedirect);
});
insecureServer.listen(insecurePort, function(){
console.log("\nRedirecting all http traffic to https\n");
});