Skip to content

Commit 586ff15

Browse files
committed
Update commentary, logging, remove unused routes.
1 parent aa2d13a commit 586ff15

File tree

1 file changed

+5
-63
lines changed

1 file changed

+5
-63
lines changed

web.js

+5-63
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Setup
22
var application_root = __dirname,
33
config = require("./config"),
4-
express = require("express"),
4+
express = require("express"),
55
path = require("path"),
66
mongoose = require('mongoose'),
77
lessMiddleware = require('less-middleware'),
@@ -37,6 +37,7 @@ function inWindow (decoded, next) {
3737
return ((result > 0) ? true : false);
3838
}
3939

40+
// CORS
4041
var allowCrossDomain = function(req, res, next) {
4142
res.header('Access-Control-Allow-Origin', '*');
4243
res.header('Access-Control-Expose-Headers', 'Content-Length, Content-Type, Location');
@@ -58,7 +59,6 @@ mongoose.connect(config.mongodb.live);
5859

5960
// config
6061
app.configure(function () {
61-
// app.use(tokenOK);
6262
app.use(allowCrossDomain);
6363
app.use(express.bodyParser());
6464
app.use(express.methodOverride());
@@ -72,9 +72,10 @@ app.configure(function () {
7272
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
7373
});
7474

75-
var Schema = mongoose.Schema; //Schema.ObjectId
75+
var Schema = mongoose.Schema;
7676

7777
// Schemas
78+
// Annotator Ranges
7879
var Ranges = new Schema({
7980
start: { type: String, required: true },
8081
end: { type: String, required: true},
@@ -120,7 +121,6 @@ app.get('/api', function (req, res) {
120121
});
121122

122123
// Search annotations
123-
// Auth: Token required to search
124124
app.get('/api/search', tokenOK, function (req, res) {
125125
var query = AnnotationModel.find({'uri': req.query.uri });
126126

@@ -140,7 +140,6 @@ app.get('/api/search', tokenOK, function (req, res) {
140140
}
141141

142142
if (req.query.sidebar) {
143-
// console.log("Sidebar request: "+ JSON.stringify(req.query));
144143
query.exec(function (err, annotations) {
145144
if (!err) {
146145
return res.send(annotations);
@@ -150,7 +149,6 @@ app.get('/api/search', tokenOK, function (req, res) {
150149
});
151150
}
152151
else {
153-
// console.log("Non-sidebar request: "+ JSON.stringify(req.query));
154152
query.exec(function (err, annotations) {
155153
if (!err) {
156154
return res.send({'rows': annotations });
@@ -159,13 +157,10 @@ app.get('/api/search', tokenOK, function (req, res) {
159157
}
160158
});
161159
}
162-
// if (req.query.permissions[read]) {};
163160
});
164161

165162
// GET to READ
166163
// List annotations
167-
// Auth: Anyone can see all annotations (no check for token)
168-
// Why?
169164
app.get('/api/annotations', tokenOK, function (req, res) {
170165
return AnnotationModel.find(function (err, annotations) {
171166
if (!err) {
@@ -177,8 +172,6 @@ app.get('/api/annotations', tokenOK, function (req, res) {
177172
});
178173

179174
// Single annotation
180-
// Auth: Anyone can see a single annotation (no check for token)
181-
// Why?
182175
app.get('/api/annotations/:id', tokenOK, function (req, res) {
183176
return AnnotationModel.findById(req.params.id, function (err, annotation) {
184177
if (!err) {
@@ -190,7 +183,6 @@ app.get('/api/annotations/:id', tokenOK, function (req, res) {
190183
});
191184

192185
// POST to CREATE
193-
// Auth: Token required to post an annotation
194186
app.post('/api/annotations', tokenOK, function (req, res) {
195187
var annotation;
196188
console.log("POST: ");
@@ -212,7 +204,6 @@ app.post('/api/annotations', tokenOK, function (req, res) {
212204
ranges: req.body.ranges,
213205
permissions: req.body.permissions
214206
});
215-
// console.log(annotation.permissions.read);
216207

217208
annotation.save(function (err) {
218209
if (!err) {
@@ -226,38 +217,7 @@ app.post('/api/annotations', tokenOK, function (req, res) {
226217
});
227218

228219
// PUT to UPDATE
229-
// Bulk update: we won't really be doing this will we?
230-
// Auth: Token required to update all annotations
231-
// Permissions: users can update only their own annotations (handled by annotator)
232-
app.put('/api/annotations', tokenOK, function (req, res) {
233-
var i, len = 0;
234-
console.log("is Array req.body.annotations");
235-
console.log(Array.isArray(req.body.annotations));
236-
console.log("PUT: (annotations)");
237-
console.log(req.body.annotations);
238-
if (Array.isArray(req.body.annotations)) {
239-
len = req.body.annotations.length;
240-
}
241-
for (i = 0; i < len; i++) {
242-
console.log("UPDATE annotation by id:");
243-
for (var id in req.body.annotations[i]) {
244-
console.log(id);
245-
}
246-
AnnotationModel.update({ "_id": id }, req.body.annotations[i][id], function (err, numAffected) {
247-
if (err) {
248-
console.log("Error on update");
249-
console.log(err);
250-
} else {
251-
console.log("updated num: " + numAffected);
252-
}
253-
});
254-
}
255-
return res.send(req.body.annotations);
256-
});
257-
258-
// Single update: This is much more likely
259-
// Auth: Token required to update one annotation
260-
// Permissions: users can update only their own annotations (handled by annotator)
220+
// Single update
261221
app.put('/api/annotations/:id', tokenOK, function (req, res) {
262222
return AnnotationModel.findById(req.params.id, function (err, annotation) {
263223
annotation._id = req.body._id;
@@ -290,25 +250,7 @@ app.put('/api/annotations/:id', tokenOK, function (req, res) {
290250
});
291251

292252
// DELETE to DESTROY
293-
// Bulk destroy all annotations
294-
// Auth: Token required to delete all annotations
295-
// NOTE: Can't think of a good use case -- commenting out. jF 09/06/2010
296-
// Permissions: user can delete only own annotations (handled by annotator)
297-
// app.delete('/api/annotations', tokenOK, function (req, res) {
298-
// AnnotationModel.remove(function (err) {
299-
// if (!err) {
300-
// console.log("removed");
301-
// return res.send('');
302-
// } else {
303-
// console.log(err);
304-
// }
305-
// });
306-
// });
307-
308-
309253
// Remove a single annotation
310-
// Auth: Token required to delete one annotation
311-
// Permissions: user can delete only own annotations (handled by annotator)
312254
app.delete('/api/annotations/:id', tokenOK, function (req, res) {
313255
return AnnotationModel.findById(req.params.id, function (err, annotation) {
314256
return annotation.remove(function (err) {

0 commit comments

Comments
 (0)