Jump To …

server.js

./
var express = require("express")
, user = require("./routes/user")
, favorite = require("./routes/favorite")
, question = require("./routes/question")
, feedback = require("./routes/feedback")
, match = require("./routes/match")
, questionresponse = require("./routes/questionresponse")
, SessionStore = require("session-mongoose")(express)
, mysql = require("./lib/mysql")
, mongo = require("./lib/dbConfig").mongo;
app = express();
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser('bob'));
app.use(express.session({
  store: new SessionStore({
      cookie: { maxAge: 900000*3},
      url: mongo,
      interval: 120000 // expiration check worker run interval in millisec (default: 60000)
  }),
  secret: "bob"
}));
app.use(express.bodyParser());
app.set('view engine', 'ejs');

global.clientPool = mysql.clientPool;

function checkAuth(req, res, next) {
  if (!req.session.userID) {
    res.set('Content-Type', 'text/json');
    res.send(401);
  } else {
    next();
  }
}
app.all("*",function(req,res,next) {

console.log("have mysql connection, pool size", clientPool.getPoolSize(), "avalible", clientPool.availableObjectsCount(),"waiting:",clientPool.waitingClientsCount());

    next();
});
app.post("/login",user.login.validator,user.login.route);
app.get("/logout",user.logout);

app.post("/user/new",user.create.validate,user.create.route);
app.post("/user/uploadPic",checkAuth,user.uploadPic);
app.get("/user/search/:query?",checkAuth,user.search);
app.get("/browse",checkAuth,user.index);
app.get("/edit",checkAuth,user.edit);
app.post("/edit",checkAuth,user.update);
app.get("/user/:userID?",checkAuth,user.view);

app.get('/matches',checkAuth,match.index);

app.post("/favorite/create",checkAuth,favorite.create);
app.post("/favorite/delete",checkAuth,favorite.delete);
app.get("/favorite",checkAuth,favorite.list);

app.post("/question/new",checkAuth,question.create);

app.post("/questionresponse/new",checkAuth,questionresponse.create.validate,questionresponse.create.route);
app.post("/questionresponse/delete",checkAuth,questionresponse.delete.validate,questionresponse.delete.route);

app.get("/question/view",checkAuth,question.view);

app.get("/question/stats/:questionID?",question.stats)
app.get('/question',question.index);

app.post("/feedback/new",checkAuth,feedback.create);

app.get("/home.html",function(req,res) {
  res.redirect("index.html");
});

app.listen(3000);

 
 

generated Tue Apr 30 2013 17:31:04 GMT-0400 (EDT)
Modfinder