xonecas.io
191
Pp

particle-play / commit 1f54299

initial commit; more to be done

sean2011-08-26 1f54299f7534312662379c16021da3c329a1c7e5

172 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

README.markdown+1−0
@@ -0,0 +1 @@
1+A link will be here
index.html+20−0
@@ -0,0 +1,20 @@
1+<!doctype html>
2+<html lang="en">
3+<head charset="utf-8">
4+
5+ <title></title>
6+ <meta name="author" content="">
7+ <meta name="description" content="">
8+
9+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
11+ <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap-1.1.0.min.css">
12+ <link rel="stylesheet" href="style.css">
13+</head>
14+<body>
15+ <h1>Particle play <small>Playing around with particles on a 2d enviroment</small></h1>
16+
17+
18+ <script src="script.js"></script>
19+</body
20+</html>
node.js+89−0
@@ -0,0 +1,89 @@
1+/* ============================================================================
2+ author: @xonecas
3+
4+ A boiler inspired by apache's .htaccess, that will serve static
5+ files off the shelf (just in case you want to get going quick)
6+ Everything else is for you to decide.
7+
8+ I will keep this up to date with current node and connect versions
9+============================================================================= */
10+
11+var connect = require('connect'),
12+ // inspect tool, I use it all the time.
13+ inspect = require('util').inspect;
14+
15+
16+/* ----------------------------
17+ your server code:
18+---------------------------- */
19+
20+
21+
22+
23+
24+
25+var routes = function (app) {
26+
27+/* ---------------------------------------------------------------------------------
28+ your routes go here
29+ you can use app.get, app.post, ...
30+ the docs are here: http://senchalabs.github.com/connect/middleware-router.html
31+---------------------------------------------------------------------------------- */
32+
33+
34+
35+
36+
37+/* ---------------------------------------------------------------------------------
38+ Keep this route last.
39+---------------------------------------------------------------------------------- */
40+ app.get('*', function (req, res, next) {
41+ var url = req.url,
42+ ua = req.headers['user-agent'];
43+
44+ // request latest IE engine or chrome frame
45+ if (ua && ua.indexOf('MSIE') &&
46+ url.match(/\.html$/) || url.match(/\.htm$/))
47+ res.setHeader('X-UA-Compatible', "IE=Edge,chrome=1");
48+
49+ // protect .files
50+ if (url.match(/(^|\/)\./))
51+ res.end("Not allowed");
52+
53+ // control cross domain using CORS (http://enable-cors.org/)
54+ res.setHeader('Access-Control-Allow-Origin', '*');
55+ res.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
56+
57+ next(); // let the static server do the rest
58+ });
59+}
60+
61+/* ----------------------------------------------------------------------------------
62+ set you cache maximum age, in milisecconds.
63+ if you don't use cache break use a smaller value
64+ start the server.
65+---------------------------------------------------------------------------------- */
66+var cache = 1000 * 60 * 60 * 24 * 30,
67+ port = 8080,
68+ htdocs = __dirname,
69+ server = connect.createServer(
70+ // http://senchalabs.github.com/connect/middleware-logger.html
71+ connect.logger(":date | :remote-addr | :method :url :status | :user-agent"),
72+ connect.query(),
73+ connect.router(routes),
74+ connect.favicon(/* path_to_icon, {maxAge: cache} */),
75+ connect.static(htdocs, {maxAge: cache})
76+ );
77+
78+server.listen(port);
79+console.log('Node up!\nPort: '+port+'\nhtdocs: '+htdocs);
80+
81+/* -----------------------------------------------------------------------------------
82+ this is a failsafe, it will catch the error silently and logged it the console
83+ while this works, you should really try to catch the errors with a try/catch block
84+ more on this here:
85+ http://nodejs.org/docs/v0.4.3/api/process.html#event_uncaughtException_
86+----------------------------------------------------------------------------------- */
87+process.on('uncaughtException', function (err) {
88+ console.log('Caught exception: ' + err);
89+});
node_modules/connect/.npmignore+11−0
@@ -0,0 +1,11 @@
1+*.markdown
2+*.md
3+.git*
4+Makefile
5+benchmarks/
6+docs/
7+examples/
8+install.sh
9+support/
10+test/
11+.DS_Store
node_modules/connect/LICENSE+24−0
@@ -0,0 +1,24 @@
1+(The MIT License)
2+
3+Copyright (c) 2010 Sencha Inc.
4+Copyright (c) 2011 LearnBoost
5+Copyright (c) 2011 TJ Holowaychuk
6+
7+Permission is hereby granted, free of charge, to any person obtaining
8+a copy of this software and associated documentation files (the
9+'Software'), to deal in the Software without restriction, including
10+without limitation the rights to use, copy, modify, merge, publish,
11+distribute, sublicense, and/or sell copies of the Software, and to
12+permit persons to whom the Software is furnished to do so, subject to
13+the following conditions:
14+
15+The above copyright notice and this permission notice shall be
16+included in all copies or substantial portions of the Software.
17+
18+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
19+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/connect/index.js+2−0
@@ -0,0 +1,2 @@
1+
2+module.exports = require('./lib/connect');
node_modules/connect/lib/connect.js+106−0
@@ -0,0 +1,106 @@
1+
2+/*!
3+ * Connect
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var HTTPServer = require('./http').Server
14+ , HTTPSServer = require('./https').Server
15+ , fs = require('fs');
16+
17+// node patches
18+
19+require('./patch');
20+
21+// expose createServer() as the module
22+
23+exports = module.exports = createServer;
24+
25+/**
26+ * Framework version.
27+ */
28+
29+exports.version = '1.6.2';
30+
31+/**
32+ * Initialize a new `connect.HTTPServer` with the middleware
33+ * passed to this function. When an object is passed _first_,
34+ * we assume these are the tls options, and return a `connect.HTTPSServer`.
35+ *
36+ * Examples:
37+ *
38+ * An example HTTP server, accepting several middleware.
39+ *
40+ * var server = connect.createServer(
41+ * connect.logger()
42+ * , connect.static(__dirname + '/public')
43+ * );
44+ *
45+ * An HTTPS server, utilizing the same middleware as above.
46+ *
47+ * var server = connect.createServer(
48+ * { key: key, cert: cert }
49+ * , connect.logger()
50+ * , connect.static(__dirname + '/public')
51+ * );
52+ *
53+ * Alternatively with connect 1.0 we may omit `createServer()`.
54+ *
55+ * connect(
56+ * connect.logger()
57+ * , connect.static(__dirname + '/public')
58+ * ).listen(3000);
59+ *
60+ * @param {Object|Function} ...
61+ * @return {Server}
62+ * @api public
63+ */
64+
65+function createServer() {
66+ if ('object' == typeof arguments[0]) {
67+ return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
68+ } else {
69+ return new HTTPServer(Array.prototype.slice.call(arguments));
70+ }
71+};
72+
73+// support connect.createServer()
74+
75+exports.createServer = createServer;
76+
77+// auto-load getters
78+
79+exports.middleware = {};
80+
81+/**
82+ * Auto-load bundled middleware with getters.
83+ */
84+
85+fs.readdirSync(__dirname + '/middleware').forEach(function(filename){
86+ if (/\.js$/.test(filename)) {
87+ var name = filename.substr(0, filename.lastIndexOf('.'));
88+ exports.middleware.__defineGetter__(name, function(){
89+ return require('./middleware/' + name);
90+ });
91+ }
92+});
93+
94+// expose utils
95+
96+exports.utils = require('./utils');
97+
98+// expose getters as first-class exports
99+
100+exports.utils.merge(exports, exports.middleware);
101+
102+// expose constructors
103+
104+exports.HTTPServer = HTTPServer;
105+exports.HTTPSServer = HTTPSServer;
106+
node_modules/connect/lib/http.js+212−0
@@ -0,0 +1,212 @@
1+
2+/*!
3+ * Connect - HTTPServer
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var http = require('http')
14+ , parse = require('url').parse
15+ , assert = require('assert');
16+
17+// environment
18+
19+var env = process.env.NODE_ENV || 'development';
20+
21+/**
22+ * Initialize a new `Server` with the given `middleware`.
23+ *
24+ * Examples:
25+ *
26+ * var server = connect.createServer(
27+ * connect.favicon()
28+ * , connect.logger()
29+ * , connect.static(__dirname + '/public')
30+ * );
31+ *
32+ * @params {Array} middleware
33+ * @return {Server}
34+ * @api public
35+ */
36+
37+var Server = exports.Server = function HTTPServer(middleware) {
38+ this.stack = [];
39+ middleware.forEach(function(fn){
40+ this.use(fn);
41+ }, this);
42+ http.Server.call(this, this.handle);
43+};
44+
45+/**
46+ * Inherit from `http.Server.prototype`.
47+ */
48+
49+Server.prototype.__proto__ = http.Server.prototype;
50+
51+/**
52+ * Utilize the given middleware `handle` to the given `route`,
53+ * defaulting to _/_. This "route" is the mount-point for the
54+ * middleware, when given a value other than _/_ the middleware
55+ * is only effective when that segment is present in the request's
56+ * pathname.
57+ *
58+ * For example if we were to mount a function at _/admin_, it would
59+ * be invoked on _/admin_, and _/admin/settings_, however it would
60+ * not be invoked for _/_, or _/posts_.
61+ *
62+ * This is effectively the same as passing middleware to `connect.createServer()`,
63+ * however provides a progressive api.
64+ *
65+ * Examples:
66+ *
67+ * var server = connect.createServer();
68+ * server.use(connect.favicon());
69+ * server.use(connect.logger());
70+ * server.use(connect.static(__dirname + '/public'));
71+ *
72+ * If we wanted to prefix static files with _/public_, we could
73+ * "mount" the `static()` middleware:
74+ *
75+ * server.use('/public', connect.static(__dirname + '/public'));
76+ *
77+ * This api is chainable, meaning the following is valid:
78+ *
79+ * connect.createServer()
80+ * .use(connect.favicon())
81+ * .use(connect.logger())
82+ * .use(connect.static(__dirname + '/public'))
83+ * .listen(3000);
84+ *
85+ * @param {String|Function} route or handle
86+ * @param {Function} handle
87+ * @return {Server}
88+ * @api public
89+ */
90+
91+Server.prototype.use = function(route, handle){
92+ this.route = '/';
93+
94+ // default route to '/'
95+ if ('string' != typeof route) {
96+ handle = route;
97+ route = '/';
98+ }
99+
100+ // wrap sub-apps
101+ if ('function' == typeof handle.handle) {
102+ var server = handle;
103+ server.route = route;
104+ handle = function(req, res, next) {
105+ server.handle(req, res, next);
106+ };
107+ }
108+
109+ // wrap vanilla http.Servers
110+ if (handle instanceof http.Server) {
111+ handle = handle.listeners('request')[0];
112+ }
113+
114+ // normalize route to not trail with slash
115+ if ('/' == route[route.length - 1]) {
116+ route = route.substr(0, route.length - 1);
117+ }
118+
119+ // add the middleware
120+ this.stack.push({ route: route, handle: handle });
121+
122+ // allow chaining
123+ return this;
124+};
125+
126+/**
127+ * Handle server requests, punting them down
128+ * the middleware stack.
129+ *
130+ * @api private
131+ */
132+
133+Server.prototype.handle = function(req, res, out) {
134+ var writeHead = res.writeHead
135+ , stack = this.stack
136+ , removed = ''
137+ , index = 0;
138+
139+ function next(err) {
140+ var layer, path, c;
141+ req.url = removed + req.url;
142+ req.originalUrl = req.originalUrl || req.url;
143+ removed = '';
144+
145+ layer = stack[index++];
146+
147+ // all done
148+ if (!layer) {
149+ // but wait! we have a parent
150+ if (out) return out(err);
151+
152+ // otherwise send a proper error message to the browser.
153+ if (err) {
154+ var msg = 'production' == env
155+ ? 'Internal Server Error'
156+ : err.stack || err.toString();
157+
158+ // output to stderr in a non-test env
159+ if ('test' != env) console.error(err.stack || err.toString());
160+
161+ res.statusCode = 500;
162+ res.setHeader('Content-Type', 'text/plain');
163+ res.end(msg);
164+ } else {
165+ res.statusCode = 404;
166+ res.setHeader('Content-Type', 'text/plain');
167+ res.end('Cannot ' + req.method + ' ' + req.url);
168+ }
169+ return;
170+ }
171+
172+ try {
173+ path = parse(req.url).pathname;
174+ if (undefined == path) path = '/';
175+
176+ // skip this layer if the route doesn't match.
177+ if (0 != path.indexOf(layer.route)) return next(err);
178+
179+ c = path[layer.route.length];
180+ if (c && '/' != c && '.' != c) return next(err);
181+
182+ // Call the layer handler
183+ // Trim off the part of the url that matches the route
184+ removed = layer.route;
185+ req.url = req.url.substr(removed.length);
186+
187+ // Ensure leading slash
188+ if ('/' != req.url[0]) req.url = '/' + req.url;
189+
190+ var arity = layer.handle.length;
191+ if (err) {
192+ if (arity === 4) {
193+ layer.handle(err, req, res, next);
194+ } else {
195+ next(err);
196+ }
197+ } else if (arity < 4) {
198+ layer.handle(req, res, next);
199+ } else {
200+ next();
201+ }
202+ } catch (e) {
203+ if (e instanceof assert.AssertionError) {
204+ console.error(e.stack + '\n');
205+ next(e);
206+ } else {
207+ next(e);
208+ }
209+ }
210+ }
211+ next();
212+};
node_modules/connect/lib/https.js+47−0
@@ -0,0 +1,47 @@
1+
2+/*!
3+ * Connect - HTTPServer
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var HTTPServer = require('./http').Server
14+ , https = require('https');
15+
16+/**
17+ * Initialize a new `Server` with the given
18+ *`options` and `middleware`. The HTTPS api
19+ * is identical to the [HTTP](http.html) server,
20+ * however TLS `options` must be provided before
21+ * passing in the optional middleware.
22+ *
23+ * @params {Object} options
24+ * @params {Array} middleawre
25+ * @return {Server}
26+ * @api public
27+ */
28+
29+var Server = exports.Server = function HTTPSServer(options, middleware) {
30+ this.stack = [];
31+ middleware.forEach(function(fn){
32+ this.use(fn);
33+ }, this);
34+ https.Server.call(this, options, this.handle);
35+};
36+
37+/**
38+ * Inherit from `http.Server.prototype`.
39+ */
40+
41+Server.prototype.__proto__ = https.Server.prototype;
42+
43+// mixin HTTPServer methods
44+
45+Object.keys(HTTPServer.prototype).forEach(function(method){
46+ Server.prototype[method] = HTTPServer.prototype[method];
47+});
node_modules/connect/lib/index.js+45−0
@@ -0,0 +1,45 @@
1+
2+/**
3+ * # Connect
4+ *
5+ * Connect is a middleware framework for node,
6+ * shipping with over 11 bundled middleware and a rich choice of
7+ * [3rd-party middleware](https://github.com/senchalabs/connect/wiki).
8+ *
9+ * Installation:
10+ *
11+ * $ npm install connect
12+ *
13+ * API:
14+ *
15+ * - [connect](connect.html) general
16+ * - [http](http.html) http server
17+ * - [https](https.html) https server
18+ *
19+ * Middleware:
20+ *
21+ * - [logger](middleware-logger.html) request logger with custom format support
22+ * - [csrf](middleware-csrf.html) Cross-site request forgery protection
23+ * - [basicAuth](middleware-basicAuth.html) basic http authentication
24+ * - [bodyParser](middleware-bodyParser.html) extensible request body parser
25+ * - [cookieParser](middleware-cookieParser.html) cookie parser
26+ * - [session](middleware-session.html) session management support with bundled [MemoryStore](middleware-session-memory.html)
27+ * - [compiler](middleware-compiler.html) static asset compiler (sass, less, coffee-script, etc)
28+ * - [methodOverride](middleware-methodOverride.html) faux HTTP method support
29+ * - [responseTime](middleware-responseTime.html) calculates response-time and exposes via X-Response-Time
30+ * - [router](middleware-router.html) provides rich Sinatra / Express-like routing
31+ * - [static](middleware-static.html) streaming static file server supporting `Range` and more
32+ * - [directory](middleware-directory.html) directory listing middleware
33+ * - [vhost](middleware-vhost.html) virtual host sub-domain mapping middleware
34+ * - [favicon](middleware-favicon.html) efficient favicon server (with default icon)
35+ * - [limit](middleware-limit.html) limit the bytesize of request bodies
36+ * - [profiler](middleware-profiler.html) request profiler reporting response-time, memory usage, etc
37+ * - [query](middleware-query.html) automatic querystring parser, populating `req.query`
38+ * - [errorHandler](middleware-errorHandler.html) flexible error handler
39+ *
40+ * Internals:
41+ *
42+ * - connect [utilities](utils.html)
43+ * - node monkey [patches](patch.html)
44+ *
45+ */
node_modules/connect/lib/middleware/basicAuth.js+93−0
@@ -0,0 +1,93 @@
1+
2+/*!
3+ * Connect - basicAuth
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var utils = require('../utils')
14+ , unauthorized = utils.unauthorized
15+ , badRequest = utils.badRequest;
16+
17+/**
18+ * Enfore basic authentication by providing a `callback(user, pass)`,
19+ * which must return `true` in order to gain access. Alternatively an async
20+ * method is provided as well, invoking `callback(user, pass, callback)`. Populates
21+ * `req.remoteUser`. The final alternative is simply passing username / password
22+ * strings.
23+ *
24+ * Examples:
25+ *
26+ * connect(connect.basicAuth('username', 'password'));
27+ *
28+ * connect(
29+ * connect.basicAuth(function(user, pass){
30+ * return 'tj' == user & 'wahoo' == pass;
31+ * })
32+ * );
33+ *
34+ * connect(
35+ * connect.basicAuth(function(user, pass, fn){
36+ * User.authenticate({ user: user, pass: pass }, fn);
37+ * })
38+ * );
39+ *
40+ * @param {Function|String} callback or username
41+ * @param {String} realm
42+ * @api public
43+ */
44+
45+module.exports = function basicAuth(callback, realm) {
46+ var username, password;
47+
48+ // user / pass strings
49+ if ('string' == typeof callback) {
50+ username = callback;
51+ password = realm;
52+ if ('string' != typeof password) throw new Error('password argument required');
53+ realm = arguments[2];
54+ callback = function(user, pass){
55+ return user == username && pass == password;
56+ }
57+ }
58+
59+ realm = realm || 'Authorization Required';
60+
61+ return function(req, res, next) {
62+ var authorization = req.headers.authorization;
63+
64+ if (req.remoteUser) return next();
65+ if (!authorization) return unauthorized(res, realm);
66+
67+ var parts = authorization.split(' ')
68+ , scheme = parts[0]
69+ , credentials = new Buffer(parts[1], 'base64').toString().split(':');
70+
71+ if ('Basic' != scheme) return badRequest(res);
72+
73+ // async
74+ if (callback.length >= 3) {
75+ var pause = utils.pause(req);
76+ callback(credentials[0], credentials[1], function(err, user){
77+ if (err || !user) return unauthorized(res, realm);
78+ req.remoteUser = user;
79+ next();
80+ pause.resume();
81+ });
82+ // sync
83+ } else {
84+ if (callback(credentials[0], credentials[1])) {
85+ req.remoteUser = credentials[0];
86+ next();
87+ } else {
88+ unauthorized(res, realm);
89+ }
90+ }
91+ }
92+};
93+
node_modules/connect/lib/middleware/bodyParser.js+92−0
@@ -0,0 +1,92 @@
1+
2+/*!
3+ * Connect - bodyParser
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var qs = require('qs');
14+
15+/**
16+ * Extract the mime type from the given request's
17+ * _Content-Type_ header.
18+ *
19+ * @param {IncomingMessage} req
20+ * @return {String}
21+ * @api private
22+ */
23+
24+function mime(req) {
25+ var str = req.headers['content-type'] || '';
26+ return str.split(';')[0];
27+}
28+
29+/**
30+ * Parse request bodies.
31+ *
32+ * By default _application/json_ and _application/x-www-form-urlencoded_
33+ * are supported, however you may map `connect.bodyParser.parse[contentType]`
34+ * to a function of your choice to replace existing parsers, or implement
35+ * one for other content-types.
36+ *
37+ * Examples:
38+ *
39+ * connect.createServer(
40+ * connect.bodyParser()
41+ * , function(req, res) {
42+ * res.end('viewing user ' + req.body.user.name);
43+ * }
44+ * );
45+ *
46+ * Since both _json_ and _x-www-form-urlencoded_ are supported by
47+ * default, either of the following requests would result in the response
48+ * of "viewing user tj".
49+ *
50+ * $ curl -d 'user[name]=tj' http://localhost/
51+ * $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://localhost/
52+ *
53+ * @return {Function}
54+ * @api public
55+ */
56+
57+exports = module.exports = function bodyParser(){
58+ return function bodyParser(req, res, next) {
59+ if ('GET' == req.method || 'HEAD' == req.method) return next();
60+ var parser = exports.parse[mime(req)];
61+ if (parser && !req.body) {
62+ var data = '';
63+ req.setEncoding('utf8');
64+ req.on('data', function(chunk) { data += chunk; });
65+ req.on('end', function(){
66+ req.rawBody = data;
67+ try {
68+ req.body = data
69+ ? parser(data)
70+ : {};
71+ } catch (err) {
72+ return next(err);
73+ }
74+ next();
75+ });
76+ } else {
77+ next();
78+ }
79+ }
80+};
81+
82+/**
83+ * Supported decoders.
84+ *
85+ * - application/x-www-form-urlencoded
86+ * - application/json
87+ */
88+
89+exports.parse = {
90+ 'application/x-www-form-urlencoded': qs.parse
91+ , 'application/json': JSON.parse
92+};
node_modules/connect/lib/middleware/compiler.js+163−0
@@ -0,0 +1,163 @@
1+
2+/*!
3+ * Connect - compiler
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var fs = require('fs')
14+ , path = require('path')
15+ , parse = require('url').parse;
16+
17+/**
18+ * Require cache.
19+ */
20+
21+var cache = {};
22+
23+/**
24+ * Setup compiler.
25+ *
26+ * Options:
27+ *
28+ * - `src` Source directory, defaults to **CWD**.
29+ * - `dest` Destination directory, defaults `src`.
30+ * - `enable` Array of enabled compilers.
31+ *
32+ * Compilers:
33+ *
34+ * - `sass` Compiles sass to css
35+ * - `less` Compiles less to css
36+ * - `coffeescript` Compiles coffee to js
37+ *
38+ * @param {Object} options
39+ * @api public
40+ */
41+
42+exports = module.exports = function compiler(options){
43+ options = options || {};
44+
45+ var srcDir = options.src || process.cwd()
46+ , destDir = options.dest || srcDir
47+ , enable = options.enable;
48+
49+ if (!enable || enable.length === 0) {
50+ throw new Error('compiler\'s "enable" option is not set, nothing will be compiled.');
51+ }
52+
53+ return function compiler(req, res, next){
54+ if ('GET' != req.method) return next();
55+ var pathname = parse(req.url).pathname;
56+ for (var i = 0, len = enable.length; i < len; ++i) {
57+ var name = enable[i]
58+ , compiler = compilers[name];
59+ if (compiler.match.test(pathname)) {
60+ var src = (srcDir + pathname).replace(compiler.match, compiler.ext)
61+ , dest = destDir + pathname;
62+
63+ // Compare mtimes
64+ fs.stat(src, function(err, srcStats){
65+ if (err) {
66+ if ('ENOENT' == err.code) {
67+ next();
68+ } else {
69+ next(err);
70+ }
71+ } else {
72+ fs.stat(dest, function(err, destStats){
73+ if (err) {
74+ // Oh snap! it does not exist, compile it
75+ if ('ENOENT' == err.code) {
76+ compile();
77+ } else {
78+ next(err);
79+ }
80+ } else {
81+ // Source has changed, compile it
82+ if (srcStats.mtime > destStats.mtime) {
83+ compile();
84+ } else {
85+ // Defer file serving
86+ next();
87+ }
88+ }
89+ });
90+ }
91+ });
92+
93+ // Compile to the destination
94+ function compile() {
95+ fs.readFile(src, 'utf8', function(err, str){
96+ if (err) {
97+ next(err);
98+ } else {
99+ compiler.compile(str, function(err, str){
100+ if (err) {
101+ next(err);
102+ } else {
103+ fs.writeFile(dest, str, 'utf8', function(err){
104+ next(err);
105+ });
106+ }
107+ });
108+ }
109+ });
110+ }
111+ return;
112+ }
113+ }
114+ next();
115+ };
116+};
117+
118+/**
119+ * Bundled compilers:
120+ *
121+ * - [sass](http://github.com/visionmedia/sass.js) to _css_
122+ * - [less](http://github.com/cloudhead/less.js) to _css_
123+ * - [coffee](http://github.com/jashkenas/coffee-script) to _js_
124+ */
125+
126+var compilers = exports.compilers = {
127+ sass: {
128+ match: /\.css$/,
129+ ext: '.sass',
130+ compile: function(str, fn){
131+ var sass = cache.sass || (cache.sass = require('sass'));
132+ try {
133+ fn(null, sass.render(str));
134+ } catch (err) {
135+ fn(err);
136+ }
137+ }
138+ },
139+ less: {
140+ match: /\.css$/,
141+ ext: '.less',
142+ compile: function(str, fn){
143+ var less = cache.less || (cache.less = require('less'));
144+ try {
145+ less.render(str, fn);
146+ } catch (err) {
147+ fn(err);
148+ }
149+ }
150+ },
151+ coffeescript: {
152+ match: /\.js$/,
153+ ext: '.coffee',
154+ compile: function(str, fn){
155+ var coffee = cache.coffee || (cache.coffee = require('coffee-script'));
156+ try {
157+ fn(null, coffee.compile(str));
158+ } catch (err) {
159+ fn(err);
160+ }
161+ }
162+ }
163+};
node_modules/connect/lib/middleware/cookieParser.js+46−0
@@ -0,0 +1,46 @@
1+
2+/*!
3+ * Connect - cookieParser
4+ * Copyright(c) 2010 Sencha Inc.
5+ * Copyright(c) 2011 TJ Holowaychuk
6+ * MIT Licensed
7+ */
8+
9+/**
10+ * Module dependencies.
11+ */
12+
13+var utils = require('./../utils');
14+
15+/**
16+ * Parse _Cookie_ header and populate `req.cookies`
17+ * with an object keyed by the cookie names.
18+ *
19+ * Examples:
20+ *
21+ * connect.createServer(
22+ * connect.cookieParser()
23+ * , function(req, res, next){
24+ * res.end(JSON.stringify(req.cookies));
25+ * }
26+ * );
27+ *
28+ * @return {Function}
29+ * @api public
30+ */
31+
32+module.exports = function cookieParser(){
33+ return function cookieParser(req, res, next) {
34+ var cookie = req.headers.cookie;
35+ if (req.cookies) return next();
36+ req.cookies = {};
37+ if (cookie) {
38+ try {
39+ req.cookies = utils.parseCookie(cookie);
40+ } catch (err) {
41+ return next(err);
42+ }
43+ }
44+ next();
45+ };
46+};
node_modules/connect/lib/middleware/csrf.js+105−0
@@ -0,0 +1,105 @@
1+
2+/*!
3+ * Connect - csrf
4+ * Copyright(c) 2011 Sencha Inc.
5+ * MIT Licensed
6+ */
7+
8+/**
9+ * Module dependencies.
10+ */
11+
12+var utils = require('../utils')
13+ , crypto = require('crypto');
14+
15+/**
16+ * CRSF protection middleware.
17+ *
18+ * By default this middleware generates a token named "_csrf"
19+ * which should be added to requests which mutate
20+ * state, within a hidden form field, query-string etc. This
21+ * token is validated against the visitor's `req.session._csrf`
22+ * property which is re-generated per request.
23+ *
24+ * The default `value` function checks `req.body` generated
25+ * by the `bodyParser()` middleware, `req.query` generated
26+ * by `query()`, and the "X-CSRF-Token" header field.
27+ *
28+ * This middleware requires session support, thus should be added
29+ * somewhere _below_ `session()` and `cookieParser()`.
30+ *
31+ * Examples:
32+ *
33+ * var form = '\n\
34+ * <form action="/" method="post">\n\
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/directory.js+222−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/errorHandler.js+100−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/favicon.js+76−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/limit.js+78−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/logger.js+299−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/methodOverride.js+38−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/profiler.js+100−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/query.js+40−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/responseTime.js+34−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/router.js+379−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/session.js+346−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/session/cookie.js+126−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/session/memory.js+131−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/session/session.js+137−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/session/store.js+59−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/static.js+219−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/middleware/vhost.js+44−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/patch.js+67−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/public/directory.html+75−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/public/error.html+13−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/public/favicon.ico+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_add.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_attach.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_code.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_copy.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_delete.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_edit.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_error.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_excel.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_find.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_gear.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_go.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_green.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_key.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_lightning.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_link.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_paintbrush.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_paste.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_red.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_refresh.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_save.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_acrobat.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_actionscript.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_add.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_c.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_camera.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_cd.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_code.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_code_red.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_coldfusion.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_compressed.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_copy.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_cplusplus.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_csharp.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_cup.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_database.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_delete.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_dvd.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_edit.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_error.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_excel.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_find.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_flash.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_freehand.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_gear.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_get.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_go.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_h.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_horizontal.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_key.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_lightning.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_link.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_magnify.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_medal.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_office.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_paint.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_paintbrush.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_paste.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_php.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_picture.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_powerpoint.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_put.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_ruby.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_stack.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_star.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_swoosh.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_text.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_text_width.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_tux.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_vector.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_visualstudio.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_width.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_word.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_world.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_wrench.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_white_zip.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_word.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/icons/page_world.png+0−0
Binary file, not shown.
node_modules/connect/lib/public/style.css+141−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/lib/utils.js+427−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/meta.json+1−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/LICENSE+19−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/README.md+54−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/index.js+1−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/mime.js+89−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/mime.types+1479−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/node.types+7−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/package.json+11−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/mime/test.js+74−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/.gitmodules+6−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/History.md+52−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/Makefile+7−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/Readme.md+49−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/benchmark.js+17−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/examples.js+48−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/index.js+2−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/lib/querystring.js+236−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/package.json+9−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/.gitignore+3−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/.gitmodules+3−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/History.md+128−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/Makefile+53−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/Readme.md+61−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/bin/expresso+856−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/docs/api.html+1080−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/docs/index.html+377−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/docs/index.md+290−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/docs/layout/foot.html+3−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/docs/layout/head.html+42−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/lib/bar.js+4−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/lib/foo.js+16−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/package.json+12−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/assert.test.js+91−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/async.test.js+12−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/bar.test.js+13−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/foo.test.js+14−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/http.test.js+146−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/serial/async.test.js+39−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/expresso/test/serial/http.test.js+48−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/.gitmodules+3−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/History.md+22−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/Makefile+6−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/Readme.md+248−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/examples/runner.js+53−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/index.js+2−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/lib/eql.js+91−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/lib/should.js+548−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/package.json+8−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/support/should/test/should.test.js+358−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/test/parse.test.js+156−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/node_modules/qs/test/stringify.test.js+95−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/package.json+24−0
Cut short: this commit's diff is over 1000 lines.
node_modules/connect/test.js+65−0
Cut short: this commit's diff is over 1000 lines.
script.js+97−0
Cut short: this commit's diff is over 1000 lines.
style.css+18−0
Cut short: this commit's diff is over 1000 lines.