sebmaster / racer-example Goto Github PK
View Code? Open in Web Editor NEWan example on how to connect racer.js and angular.js
an example on how to connect racer.js and angular.js
is it possible you update your example for racer 0.6?
Hello,I was testing this Github example ,When i checked that check box ,the "ng-change="save(data)" statement will excute,but i while running i am getting the following error.Can you try to resolve this error or find out anything i am missing.
Error:
TypeError: Cannot read property 'constructor' of null
at extendObject (http://localhost:8888/script.js:6:11)
at extendObject (http://localhost:8888/script.js:23:15)
at extendObject (http://localhost:8888/script.js:28:11)
at extendObject (http://localhost:8888/script.js:23:15)
at extendObject (http://localhost:8888/script.js:28:11)
at extendObject (http://localhost:8888/script.js:23:15)
at extendObject (http://localhost:8888/script.js:28:11)
at Model.model.get (http://localhost:8888/script.js:52:20)
at Object.TodoCtrl.$scope.save (http://localhost:8888/app.js:21:32)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js:74:98
When use ssl in racer-Angular shows bellow error
The page at 'https:/xxxxxxxxx/client#/?domain=12345678&user=false' was loaded over HTTPS, but displayed insecure content from 'http://xxxxxxxxxxxx/socket.io/?domain=12345678&EIO=2&transport=polling&t=1407771049675-1&sid=XkGnrBb-_4PSuW9zAAAQ': this content should also be loaded over HTTPS.
I finally got around to wanting to see this example running and polishing it up with some refactoring and adding validation and authorization logic etc. However, having trouble running it...
The README is very brief on this.
$ node app.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
$ redis-server
[20051] 16 Nov 11:38:18.628 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[20051] 16 Nov 11:38:18.632 * Max number of open files set to 10032
[20051] 16 Nov 11:38:18.632 # Opening port 6379: bind: Address already in use
$ mongod
Sat Nov 16 11:41:30 [initandlisten] MongoDB starting : pid=20086 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=kristiadrupsair
Sat Nov 16 11:41:30 [initandlisten]
Sat Nov 16 11:41:30 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Sat Nov 16 11:41:30 [initandlisten] db version v2.2.3, pdfile version 4.5
Sat Nov 16 11:41:30 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Sat Nov 16 11:41:30 [initandlisten] build info: Darwin bs-osx-106-x86-64-1.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Sat Nov 16 11:41:30 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" }
Sat Nov 16 11:41:30 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /usr/local/var/mongodb/mongod.lock. Is a mongod instance already running?, terminating
So both mongod and redis db servers are clearly running locally.
I go to http://localhost:8081/
enter a value in the input like hello and press ENTER or submit and nothing happens :(
I made a small change in the code to use the local mongo and redis databases. Shouldn't this work? What am I missing? Please update the README to give more details for running it. Thanks Seb :)
var racer = require('racer');
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var livedb_mongo = require('livedb-mongo')
var livedb = livedb_mongo('localhost:27017/test?auto_reconnect', {safe:true});
var redis = require('redis-url').connect();
var store = racer.createStore({
server: server,
db: livedb,
redis: redis
});
Hi Sebastian,
I'm still trying to wrap my head around your magic code. This part is still very much magic to me!
app.get('/model', function (req, res) {
var model = store.createModel();
model.subscribe('entries', function (err, entries) {
if (err) {
res.status(500);
res.send(err);
} else {
model.bundle(function (err, bundle) {
res.send(JSON.stringify(bundle));
});
}
});
});
// huh!?
store.bundle(__dirname + '/client.js', function (err, js) {
app.get('/script.js', function (req, res) {
res.type('js');
res.send(js);
});
});
And on the client you init racer using:
$http.get('/model').success(function (data) {
racer.init(data);
});
How does this all work? Especially the last part: store.bundle
is very cryptic!
Looks like you are sending a complete script.js file back to the client. Does this file contain the whole racer model as json, which is then evaluated on the client and stored as the local racer model on first connect? Wauw!
I would like to achieve the same kind of magic using socket.io. Could you help me achieve this perhaps?
Thanks :)
Provide a default of localhost configurations but check for ENV REDISCLOUD_URL
and MONGOLAB_URI
and if they are set use those instead.
I used this app.js file and made my own app using angular.js.when i typed the my url name on the browser address bar the home page should loaded but in my case i am getting the home page as blank looks like white page.when i saw console i got one error after some second "http://localhost:8888/model" not found.Can you please help me for getting my full home page. Actually i am getting the following error in .
Unhandled document message:[c:null,d:null]
My App.js file is given below.
var racer = require('racer'),
express = require('express'),
cookieParser = require('cookie-parser'),
redis = require("redis").createClient(6379,'127.0.0.1'),
bodyParser = require('body-parser'),
user = require("redis").createClient(6379,'127.0.0.1'),
session = require('express-session'),
RedisStore = require('connect-redis')(session),
app = express();
var mongo = require('mongojs');
db = 'entries',
collections = ['admin,entries'],
db = mongo.connect('127.0.0.1:27017/'+db, collections);
htpp = require('http'),
server = htpp.createServer(app);
//Create Store for redis and mongodb
var store = racer.createStore({
server: server,
db: require('livedb-mongo')('127.0.0.1:27017/test?auto_reconnect', {
safe: true
}),
redis: require('redis-url').connect('redis://127.0.0.1: 6379')
});
console.log('store',store);
//MiddleWare
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname));
app.use(require('racer-browserchannel')(store));
app.use(bodyParser.json({
limit: '50mb'
}));
app.use(bodyParser.urlencoded({
limit: '50mb',
extended: true
}));
app.use(cookieParser());
app.use(session({
secret: "kqsdjfmlksdhfhzirzeoibrzecrbzuzefcuercazeafxzeokwdfzeijfxcerig",
store: new RedisStore({
host: '127.0.0.1',
port: 6379,
client: redis
})
}));
app.get('/',function(req,res){
res.sendfile('views/home.html');
});
app.get('/model', function (req, res) {
var model = store.createModel();
model.subscribe('entries', function (err, entries) {
if (err) {
res.status(500);
res.send(err);
} else {
model.bundle(function (err, bundle) {
res.send(JSON.stringify(bundle));
});
}
});
});
store.bundle(__dirname + '/client.js', function (err, js) {
app.get('/script.js', function (req, res) {
res.type('js');
res.send(js);
});
});
server.listen(8888);
console.log('server listening at the port'+8888);
Please help me for the solution.
Hi there,
First off, thanks for putting this example together. I setup a mongolab db and I have a local redis instance running on port 6379.
when i run the node app I am able to browse to the Todo form, however when I try to add an entry Node prints out this error:
Error: Cannot use a writeConcern without a provided callback
at Db.ensureIndex (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:1218:11)
at Collection.ensureIndex (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/collection.js:1094:11)
at EventEmitter. (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/lib/mongoskin/utils.js:68:23)
at EventEmitter.g (events.js:175:14)
at EventEmitter.emit (events.js:98:17)
at null. (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/lib/mongoskin/collection.js:129:24)
at Db.collection (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:484:44)
at null. (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/lib/mongoskin/collection.js:119:12)
at SkinDb.open (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/lib/mongoskin/db.js:79:19)
at SkinCollection.open (/Library/WebServer/Documents/racer-example/node_modules/livedb-mongo/node_modules/mongoskin/lib/mongoskin/collection.js:114:19)
I also see a failed GET request in Chrome console which prints out:
GET http://localhost:8081/channel/test?OSID=5iy6efx9&OAID=2&VER=8&MODE=init&zx=jv5oxj5lng2p&t=1 bcsocket-uncompressed.js:1818
Thanks!
Nolan
The error is occurring while I am adding a todo.
Trace: { [MongoError: Modifiers and non-modifiers cannot be mixed]
name: 'MongoError',
err: 'Modifiers and non-modifiers cannot be mixed',
code: 10154,
n: 0,
connectionId: 4,
ok: 1 } at D:\node\racer-example\node_modules\racer\node_modules\share\lib\server\se
ssion.js:591:19 at D:\node\racer-example\node_modules\racer\node_modules\share\lib\server\us
eragent.js:294:23 at D:\node\racer-example\node_modules\racer\node_modules\share\node_modules\
livedb\lib\index.js:511:31 at null.<anonymous> (D:\node\racer-example\node_modules\livedb-mongo\node_mo
dules\mongoskin\node_modules\mongodb\lib\mongodb\collection.js:477:9)
at g (events.js:175:14) at EventEmitter.emit (events.js:106:17)
at Server.Base._callHandler (D:\node\racer-example\node_modules\livedb-mongo\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\connection\base.js:130:25) at D:\node\racer-example\node_modules\livedb-mongo\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\connection\server.js:522:20 at MongoReply.parseBody (D:\node\racer-example\node_modules\livedb-mongo\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:132:5) at null.<anonymous> (D:\node\racer-example\node_modules\livedb-mongo\node_mo
dules\mongoskin\node_modules\mongodb\lib\mongodb\connection\server.js:481:22)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.