Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
db.close();
process.exit(1);
}
});
server = http.createServer( function(req, res) {
fs.readFile('index.html', function(err, page) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(page);
res.end();
});
});
server.listen(8080);
// now.js code
var everyone = require("now").initialize(server, {socketio: {'transports': ['xhr-polling']}});
// publish meme
everyone.now.publish = function(meme) {
if(meme.name && meme.text.line1 && meme.text.line2) {
db.collection('memes', function(err, collection) {
// add a date field and save
meme.date = Date.now();
collection.insert(meme, function(err) {
if(!err)
everyone.now.receiveMeme(meme);
});
});
}
};
// retrieve the latest few memes of a name. If there is no name, retrieve a mixture
});
/*
var html = "";
res.send(html);
*/
res.send(JSON.stringify(nowUsersList));
});
// ------------------------------------------------------------
// ------------------------------------------------------------
var localFileIsMostRecent = []; // an array of flags indicating if the file has been modified since last save.
var nowjs = require("now");
var everyone = nowjs.initialize(server);
// ------ REALTIME NOWJS COLLABORATION ------
//var nowcollab = require("../CHAOS/nowcollab");
//nowcollab.initialize(nowjs, everyone, true);
//-------------------------------------------
nowjs.on('connect', function () {
//console.log("CONNECT > " + this.user.clientId);
this.user.teamID = teamID;
if(this.now.teamID != ''){
this.user.teamID = this.now.teamID;
}
//console.log(this.user);
//console.log(everyone.users);
//console.log(" >> PROJECT="+this.user.teamID);
// hack to get out best guess at the user (since now.js doesn't give us the request object or session!);
var u = {}; //(Auth || {}).getUserFromCache(decodeURIComponent(this.user.cookie['_chaos.auth'])) || {};
// now populate it..
response.writeHead(200, getContentType(filename));
response.write(file, "binary");
response.end();
});
});
});
httpServer.on('error', function (err) {
// this catches EADDRINUSE and makes sure node doesn't quit
console.log('verhicle api: error on vehicle sim server: ' + err);
});
try {
// FIXME this fails when this service is loaded more than once on one host
// as the port will already be taken
httpServer.listen(9898);
var nowjs = require('now');
var everyone = nowjs.initialize(httpServer);
var _listeners = new Object();
} catch (e) {
console.log('The Vehicle Simulator requires the node-module now. You can install it by the following command: npm install now.');
}
var gear = '11';
var tcData = new Object();
tcData.s1 = 48.5;
tcData.s2 = 46.5;
tcData.c1 = 5.7;
tcData.c2 = 6.1;
tcData.d = 33.3;
tcData.m = 11298;
tcData.r = 456;
var psrData = new Object();
psrData.ol = 255;
psrData.l = 255;
var SolveSchema = new Schema({
turns:[TurnSchema],
gameName: String,
inspectSec: Number,
solveMillis: Number
});
//initializing models
var Turn = mongoose.model('Turn', TurnSchema);
var Solve = mongoose.model('Solve', SolveSchema);
httpServer.listen(conf.server.port);
// TODO - i've disabled websockets because they're making chrome crash...
var everyone = nowjs.initialize(httpServer);
//var everyone = nowjs.initialize(httpServer, {socketio: {transports: ['xhr-polling', 'jsonp-polling']}});
function UserSet() {
this.nick_user = {};
this.clientId_user = {};
this.addUser = function(user) {
assert.ok(!(user.nick in that.nick_user));
assert.ok(!(user.clientId in that.clientId_user));
that.nick_user[user.nick] = user;
that.clientId_user[user.clientId] = user;
};
this.removeUser = function(user) {
var userByClientId = that.clientId_user[user.clientId];
var userByNick = that.nick_user[user.nick];
assert.equal(userByClientId, userByNick);
assert.equal(userByClientId, user);
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
function require_twitter_login(req, res, next) {
if(!req.session.oauth_access_token) {
res.redirect("/twitter_login?action="+querystring.escape(req.originalUrl));
return;
}
next();
};
var everyone = nowjs.initialize(app);
var users = [];
// Routes
app.get('/', require_twitter_login, function(req, res){
res.render('index', {
title: 'Express'
});
});
app.get("/twitter_login", function (req, res) {
var oa = new OAuth("https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token",
settings.twitter.key,
settings.twitter.secret,
"1.0",
exports.listen = function(port, callback){
var app = express();
app.use(express.static(__dirname + '/../client'));
server = require('http').createServer(app);
var everyone = nowjs.initialize(server, { socketio: { transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'] } });
everyone.now.getJqueryScriptText = function(callback){
return callback(null, _jqCache);
};
everyone.now.setup = function(){
var driver = new Driver(this.now);
this.now.sendConsoleLog = function(text, location){
driver.events.emit('console.log', text, location);
};
this.now.sendConsoleWarn = function(text, location){
driver.events.emit('console.warn', text, location);
};
var server = require('http').createServer(function (req, response) {
fs.readFile(__dirname + '/multiroomchat.html', function (err, data) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
response.write(data);
response.end();
});
});
var port = process.env.PORT || 8080;
server.listen(port);
console.log("server listening on port " + String(port));
var nowjs = require("now");
var everyone = nowjs.initialize(server, {
socketio: {
transports: ['xhr-polling', 'jsonp-polling']
}
});
nowjs.on('connect', function () {
this.now.firstRoom = "lobby";
nowjs.getGroup(this.now.firstRoom).addUser(this.user.clientId);
});
nowjs.on('disconnect', function () {
console.log("Someone left with client id", this.user.clientId);
});
* can use data from a node.js socket connection
*
* @author: Dominic Böttger
* @date: 2011/09/04
*/
var sys = require('sys');
var express = require('express'),
sys = require('sys'),
app = module.exports = express.createServer(),
models = require('./model'),
Person = models.Person;
var app = module.exports = express.createServer();
var everyone = require("now").initialize(app);
//Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
module.exports = clientpipe.piper = function(server){//初始化整个项目,传入server对象
everyone = nowjs.initialize(server);
clientpipe._ready();
};
module.exports.addsyn = clientpipe.addsyn;//同步
var app = express.createServer();
app.register('.html', require('ejs'));
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.set('view options', {layout: false});
app.use(express.static(__dirname + '/'));
app.use(express.static(__dirname + '/node_modules/backbone-nowjs/'));
app.get('/', function(req, res) {
res.render('index.html');
});
app.listen(port);
var everyone = nowjs.initialize(app);
var todos = new Backbone.Backend();
Backbone.connector.connect(nowjs, everyone, {todos: todos});