hopjs
Version:
A RESTful declarative API framework, with stub generators for Shell, and Android
96 lines (69 loc) • 1.94 kB
JavaScript
/**
* Module dependencies.
*/
var Hop = require("./../../index");
var express= require('express');
var RedisStore = require('connect-redis')(express);
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var sessionStore = new RedisStore();
var path = require('path');
Hop.enableCaching();
Hop.enableEvents();
require('./user');
server.listen(3000);
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.urlencoded());
app.use(express.json());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session({
store: sessionStore
}));
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.engine("jade",require('jade').__express);
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get("/",function(req,res){
res.render("index",{Hop: Hop});
});
app.get("/test",function(req,res){
console.log("TEST");
setTimeout(function(){
res.send("foo");
},5000);
});
app.get("/bar",function(req,res){
console.log("TEST");
setTimeout(function(){
res.send("foo");
},5000);
});
/*
Browser
-> auth
code <- (Store in session)
-> emit auth (code)
(store code in store)
-> subscribe (channel)
Server
internalEvent.emit -> find all sockets that are subscribed to said channel and send
*/
/*
map of channels /foo/:fooId
-> find the channel, see if a auth function exists on the channel
-> if so run auth function
-> add suspecific channel /foo/7 and socket
Every so often go through our list of channels and see if the sockets are still active, if not axe them
*/
Hop.apiHook("/api/1.0/",app);
Hop.hookSocketIO(io);