Unverified Commit a3c0c70a authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Merge branch 'addRedis' into 1.0

parents 91c35e8f 09df8c40
...@@ -9,8 +9,10 @@ var mongooseRedisCache = require("mongoose-redis-cache"); ...@@ -9,8 +9,10 @@ var mongooseRedisCache = require("mongoose-redis-cache");
// Load site wide configurations // Load site wide configurations
var config = require('./config'); var config = require('./config');
// Load in Routes
var routes = require('./routes/index'); var routes = require('./routes/index');
//var api = require('./routes/api'); var docs = require('./routes/docs');
var apiV1 = require('./routes/api/v1');
var app = express(); var app = express();
...@@ -39,7 +41,8 @@ var populateDB = require('./setup/populateDB'); ...@@ -39,7 +41,8 @@ var populateDB = require('./setup/populateDB');
populateDB(); populateDB();
app.use('/', routes); app.use('/', routes);
//app.use('/api/', api); app.use('/docs', docs);
app.use('/api/v1', apiV1);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
......
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Semester = require('../../models/Semester');
// Load site wide configurations
var config = require('../../config');
// GET ical file
var jsonSlugCache = { slugs: [] };
router.get('/json/classes/:SEMSLUG', function(req, res, next) {
var slug = req.params['SEMSLUG'];
if (jsonSlugCache[slug])
{
jsonSlugCache[slug].timesUsed++;
console.log(jsonSlugCache[slug].timesUsed)
res.send(jsonSlugCache[slug]['value']);
}
else {
// find each person with matching slug
var query = Semester.findOne({ 'slug': slug });
query.select('-_id -classes._id -classes.session_templates._id');
query.lean().exec(function (err, semester) {
if (err || (! semester)) {
res.json({
'results' : 'error, try something different'
})
}
else {res.json(semester);}
})
}
});
module.exports = router;
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Semester = require('../models/Semester');
// Load site wide configurations
var config = require('../config');
router.get('/', function(req, res, next) {
res.render('docs', { config });
})
module.exports = router;
...@@ -6,42 +6,6 @@ var Semester = require('../models/Semester'); ...@@ -6,42 +6,6 @@ var Semester = require('../models/Semester');
// Load site wide configurations // Load site wide configurations
var config = require('../config'); var config = require('../config');
router.get('/api/json/classes/:SEMSLUG/:CRNS', function(req, res, next) {
var slug = req.params['SEMSLUG'];
var crns = req.params['CRNS'].split(',');
});
// GET entire semester
router.get('/api/json/classes/:SEMSLUG', function(req, res, next) {
var slug = req.params['SEMSLUG'];
if (jsonSlugCache[slug])
{
jsonSlugCache[slug].timesUsed++;
console.log(jsonSlugCache[slug].timesUsed)
res.send(jsonSlugCache[slug]['value']);
}
else {
// find each person with matching slug
var query = Semester.findOne({ 'slug': slug });
query.select('-_id -classes._id -classes.session_templates._id');
query.lean().exec(function (err, semester) {
if (err || (! semester)) {
res.json({
'error' : 'semester not found'
})
}
else {res.json(semester);}
})
}
});
// END API SECTION
router.get('/docs', function(req, res, next) {
res.render('docs', { config });
})
/* GET home page. */ /* GET home page. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
res.render('index', { config }); res.render('index', { config });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment