Skip to content
This repository has been archived by the owner on Oct 9, 2021. It is now read-only.

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Mar 22, 2013
1 parent bfacfa4 commit c6ed84e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion server.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ app.use(function (req, res, next) {
"use strict"; "use strict";


var apikeyMatches = false; var apikeyMatches = false;

if(req.headers.origin && req.query.apikey) { if(req.headers.origin && req.query.apikey) {
//TODO: look up host in couchdb and only send the A-OK if it matches the origin header
db.get(req.query.apikey, function (err, doc) { db.get(req.query.apikey, function (err, doc) {
if (err) return next(err);
console.log(doc.host);
console.log(req.headers.origin);
if (doc.host === req.headers.origin) { if (doc.host === req.headers.origin) {
console.log('allowed');
res.header('Access-Control-Allow-Origin', req.headers.origin); res.header('Access-Control-Allow-Origin', req.headers.origin);
apikeyMatches = true; apikeyMatches = true;


Expand Down
2 changes: 1 addition & 1 deletion static/UCSF.Person.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions static/UCSF.Person.src.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var UCSF = (function () {
if (XHRobj.status === 200 && success) { if (XHRobj.status === 200 && success) {
success(JSON.parse(XHRobj.responseText)); success(JSON.parse(XHRobj.responseText));
} else { } else {
failure(XHRobj.statusText); failure(XHRobj);
} }
} }
}, },
Expand All @@ -57,7 +57,7 @@ var UCSF = (function () {


Person: { Person: {
search: function (options, success, failure ) { search: function (options, success, failure ) {
failure = failure || function (msg) {window.alert(msg);}; failure = failure || function (obj) {window.alert(obj.statusText||'An error occurred. Please try again.');};
var reqString = UCSF.createRequestString('http://apis.ucsf.edu/person/search', options); var reqString = UCSF.createRequestString('http://apis.ucsf.edu/person/search', options);
var xhr = UCSF.createCORSRequest('GET', reqString, success, failure); var xhr = UCSF.createCORSRequest('GET', reqString, success, failure);
if (! xhr) { if (! xhr) {
Expand Down
Loading

0 comments on commit c6ed84e

Please sign in to comment.