mirror of
https://github.com/jcreek/phldnhack.git
synced 2026-07-12 18:43:43 +00:00
test
This commit is contained in:
+25
-2
@@ -3,8 +3,12 @@ var express = require('express');
|
||||
var app = express();
|
||||
app.use(express.static('../build'))
|
||||
|
||||
app.get('/', function(req, res){
|
||||
res.send(fs.readFileSync('../build/index.html'));
|
||||
var mongojs = require('mongojs');
|
||||
|
||||
var db = mongojs('test', ['class', 'student']);
|
||||
|
||||
app.get('/view/:viewType/:dataType/:id', function(req, res){
|
||||
res.send(fs.readFileSync('../build/index.html', 'utf8'));
|
||||
});
|
||||
|
||||
app.get('/sample', function(req, res){
|
||||
@@ -14,5 +18,24 @@ app.get('/sample', function(req, res){
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/data/:type/:id', function(req, res){
|
||||
if(req.params.type === 'class') {
|
||||
db.class.findOne({_id: mongojs.ObjectId(req.params.id)}, function(err, classDoc){
|
||||
if(err)
|
||||
throw new Error('Error finding class');
|
||||
db.student.find({class:req.params.id}, function(err, students){
|
||||
res.send({
|
||||
class:classDoc,
|
||||
students:students
|
||||
});
|
||||
});
|
||||
});
|
||||
} else if(req.params.type === 'student') {
|
||||
db.student.find({_id:mongojs.ObjectId(req.params.id)}, function(err, student){
|
||||
res.send(student);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
app.listen(1337);
|
||||
|
||||
Reference in New Issue
Block a user