Sails app

This commit is contained in:
Ben Ramey
2014-03-08 18:32:43 -06:00
parent fb64ad1f45
commit 2a34de5580
44 changed files with 5802 additions and 0 deletions

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

0
assets/images/.gitkeep Normal file
View File

0
assets/js/.gitkeep Normal file
View File

71
assets/js/app.js Normal file
View File

@@ -0,0 +1,71 @@
/**
* app.js
*
* This file contains some conventional defaults for working with Socket.io + Sails.
* It is designed to get you up and running fast, but is by no means anything special.
*
* Feel free to change none, some, or ALL of this file to fit your needs!
*/
(function (io) {
// as soon as this file is loaded, connect automatically,
var socket = io.connect();
if (typeof console !== 'undefined') {
log('Connecting to Sails.js...');
}
socket.on('connect', function socketConnected() {
// Listen for Comet messages from Sails
socket.on('message', function messageReceived(message) {
///////////////////////////////////////////////////////////
// Replace the following with your own custom logic
// to run when a new message arrives from the Sails.js
// server.
///////////////////////////////////////////////////////////
log('New comet message received :: ', message);
//////////////////////////////////////////////////////
});
///////////////////////////////////////////////////////////
// Here's where you'll want to add any custom logic for
// when the browser establishes its socket connection to
// the Sails.js server.
///////////////////////////////////////////////////////////
log(
'Socket is now connected and globally accessible as `socket`.\n' +
'e.g. to send a GET request to Sails, try \n' +
'`socket.get("/", function (response) ' +
'{ console.log(response); })`'
);
///////////////////////////////////////////////////////////
});
// Expose connected `socket` instance globally so that it's easy
// to experiment with from the browser console while prototyping.
window.socket = socket;
// Simple log function to keep the example simple
function log () {
if (typeof console !== 'undefined') {
console.log.apply(console, arguments);
}
}
})(
// In case you're wrapping socket.io to prevent pollution of the global namespace,
// you can replace `window.io` with your own `io` here:
window.io
);

166
assets/js/sails.io.js Normal file
View File

@@ -0,0 +1,166 @@
/**
* sails.io.js
*
* This file allows you to send and receive socket.io messages to & from Sails
* by simulating a REST client interface on top of socket.io.
*
* It models its API after the $.ajax pattern from jQuery you might be familiar with.
*
* So to switch from using AJAX to Socket.io, instead of:
* `$.post( url, [data], [cb] )`
*
* You would use:
* `socket.post( url, [data], [cb] )`
*
* For more information, visit:
* http://sailsjs.org/#documentation
*/
(function (io) {
// We'll be adding methods to `io.SocketNamespace.prototype`, the prototype for the
// Socket instance returned when the browser connects with `io.connect()`
var Socket = io.SocketNamespace;
/**
* Simulate a GET request to sails
* e.g.
* `socket.get('/user/3', Stats.populate)`
*
* @param {String} url :: destination URL
* @param {Object} params :: parameters to send with the request [optional]
* @param {Function} cb :: callback function to call when finished [optional]
*/
Socket.prototype.get = function (url, data, cb) {
return this.request(url, data, cb, 'get');
};
/**
* Simulate a POST request to sails
* e.g.
* `socket.post('/event', newMeeting, $spinner.hide)`
*
* @param {String} url :: destination URL
* @param {Object} params :: parameters to send with the request [optional]
* @param {Function} cb :: callback function to call when finished [optional]
*/
Socket.prototype.post = function (url, data, cb) {
return this.request(url, data, cb, 'post');
};
/**
* Simulate a PUT request to sails
* e.g.
* `socket.post('/event/3', changedFields, $spinner.hide)`
*
* @param {String} url :: destination URL
* @param {Object} params :: parameters to send with the request [optional]
* @param {Function} cb :: callback function to call when finished [optional]
*/
Socket.prototype.put = function (url, data, cb) {
return this.request(url, data, cb, 'put');
};
/**
* Simulate a DELETE request to sails
* e.g.
* `socket.delete('/event', $spinner.hide)`
*
* @param {String} url :: destination URL
* @param {Object} params :: parameters to send with the request [optional]
* @param {Function} cb :: callback function to call when finished [optional]
*/
Socket.prototype['delete'] = function (url, data, cb) {
return this.request(url, data, cb, 'delete');
};
/**
* Simulate HTTP over Socket.io
* @api private :: but exposed for backwards compatibility w/ <= sails@~0.8
*/
Socket.prototype.request = request;
function request (url, data, cb, method) {
var socket = this;
var usage = 'Usage:\n socket.' +
(method || 'request') +
'( destinationURL, dataToSend, fnToCallWhenComplete )';
// Remove trailing slashes and spaces
url = url.replace(/^(.+)\/*\s*$/, '$1');
// If method is undefined, use 'get'
method = method || 'get';
if ( typeof url !== 'string' ) {
throw new Error('Invalid or missing URL!\n' + usage);
}
// Allow data arg to be optional
if ( typeof data === 'function' ) {
cb = data;
data = {};
}
// Build to request
var json = io.JSON.stringify({
url: url,
data: data
});
// Send the message over the socket
socket.emit(method, json, function afterEmitted (result) {
var parsedResult = result;
if (result && typeof result === 'string') {
try {
parsedResult = io.JSON.parse(result);
} catch (e) {
if (typeof console !== 'undefined') {
console.warn("Could not parse:", result, e);
}
throw new Error("Server response could not be parsed!\n" + result);
}
}
// TODO: Handle errors more effectively
if (parsedResult === 404) throw new Error("404: Not found");
if (parsedResult === 403) throw new Error("403: Forbidden");
if (parsedResult === 500) throw new Error("500: Server error");
cb && cb(parsedResult);
});
}
}) (
// In case you're wrapping socket.io to prevent pollution of the global namespace,
// you can replace `window.io` with your own `io` here:
window.io
);

3328
assets/js/socket.io.js Normal file

File diff suppressed because it is too large Load Diff

6
assets/robots.txt Normal file
View File

@@ -0,0 +1,6 @@
# The robots.txt file is used to control how search engines index your live URLs.
# See http://www.robotstxt.org/wc/norobots.html for more information.
#
# To prevent search engines from seeing the site altogether, uncomment the next two lines:
# User-Agent: *
# Disallow: /

0
assets/styles/.gitkeep Normal file
View File