forked from coolaj86/walnut.js
		
	flatten modules, eager load sessions
This commit is contained in:
		
							parent
							
								
									a21c503b6e
								
							
						
					
					
						commit
						7151868c62
					
				
							
								
								
									
										73
									
								
								bin/walnut
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								bin/walnut
									
									
									
									
									
								
							| @ -2,3 +2,76 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| require('../walnut.js'); | 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); | ||||||
|  | |||||||
							
								
								
									
										117
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								package.json
									
									
									
									
									
								
							| @ -37,31 +37,96 @@ | |||||||
|   }, |   }, | ||||||
|   "homepage": "https://github.com/Daplie/walnut", |   "homepage": "https://github.com/Daplie/walnut", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "bluebird": "^2.9.9", |     "accepts": "^1.2.5", | ||||||
|     "body-parser": "^1.12.0", |     "bluebird": "2.x", | ||||||
|     "check-ip-address": "^1.1.0", |     "body-parser": "1.x", | ||||||
|     "cli": "^0.6.5", |     "btoa": "1.x", | ||||||
|     "compression": "^1.4.1", |     "bytes": "^1.0.0", | ||||||
|     "connect": "^3.3.4", |     "compression": "1.x", | ||||||
|     "connect-cors": "^0.5.6", |     "connect": "3.x", | ||||||
|     "connect-query": "^0.2.0", |     "connect-cors": "0.5.x", | ||||||
|     "cookie-parser": "^1.3.4", |     "connect-query": "0.2.x", | ||||||
|     "errorhandler": "^1.3.4", |     "connect-recase": "1.x", | ||||||
|     "escape-string-regexp": "^1.0.2", |     "connect-send-error": "1.x", | ||||||
|     "express": "^4.11.2", |     "content-type": "^1.0.1", | ||||||
|     "express-session": "^1.10.3", |     "cookie": "^0.1.2", | ||||||
|     "foreachasync": "^5.0.5", |     "cookie-parser": "1.x", | ||||||
|     "http-proxy": "^1.8.1", |     "cookie-session": "1.x", | ||||||
|     "human-readable-ids": "^1.0.1", |     "cookie-signature": "^1.0.6", | ||||||
|     "nat-pmp": "0.0.3", |     "crc": "^3.2.1", | ||||||
|     "node-acme": "0.0.1", |     "debug": "^2.1.3", | ||||||
|     "request": "^2.53.0", |     "depd": "^1.0.0", | ||||||
|     "serve-favicon": "^2.2.0", |     "destroy": "^1.0.3", | ||||||
|     "serve-index": "^1.6.2", |     "dom-storage": "2.x", | ||||||
|     "serve-static": "^1.9.1", |     "ee-first": "^1.1.0", | ||||||
|     "ssl-root-cas": "^1.1.7", |     "errorhandler": "1.x", | ||||||
|     "urlrouter": "^0.5.4", |     "es6-promise": "2.x", | ||||||
|     "vhost": "^3.0.0", |     "escape-html": "^1.0.1", | ||||||
|     "xml2js": "^0.4.5" |     "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
									
									
									
									
									
								
							
							
						
						
									
										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"); |  | ||||||
| }); |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user