Skip to content
Browse files

Make it work

  • Loading branch information...
1 parent d34fc1e commit ed3883f239f36e52ff475e599ec420b488f3b4b6 @galfert galfert committed Feb 21, 2012
Showing with 30 additions and 14 deletions.
  1. +5 −4 lib/express-storage.js
  2. +25 −10 server.js
View
9 lib/express-storage.js
@@ -36,7 +36,7 @@ exports.storage = (function() {
redisClient.get('token:'+userId+':'+token, function(err, categoriesStr) {
var categories;
try {
- categories = JSON.parse(categoriesStr);
+ categories = categoriesStr.split(',');
} catch(e) {
console.log('5-0');
callback(false);
@@ -76,7 +76,7 @@ exports.storage = (function() {
redisClient.set('value:'+reqObj.userId+':'+reqObj.category+':'+reqObj.key, reqObj.value, function(err, data) {
console.log('redis says:');console.log(err);console.log(data);
redisClient.quit();
- callback(200);
+ callback(200, data);
});
} else if (reqObj.method=='DELETE') {
console.log('it\'s a DELETE');
@@ -129,7 +129,7 @@ exports.storage = (function() {
redisClient.get('user:'+userId, function(err, data) {
if(data == password) {
console.log('creating token "'+token+'" for user "'+userId+'", categories: '+JSON.stringify(categories));
- redisClient.set('token:'+userId+':'+token, JSON.stringify(categories), function(err, data) {
+ redisClient.set('token:'+userId+':'+token, categories, function(err, data) {
redisClient.quit();
callback(true);
});
@@ -145,6 +145,7 @@ exports.storage = (function() {
addToken: addToken,
removeToken: removeToken,
addUser: addUser,
- createToken: createToken
+ createToken: createToken,
+ doReq: doReq
};
})();
View
35 server.js
@@ -38,7 +38,7 @@ app.get('/', function(req, res){
});
});
-app.get('/.well-known', function(req, res){
+app.get('/.well-known/host-meta', function(req, res){
res.header('Access-Control-Allow-Origin', '*')
res.header('Content-Type', 'application/xrd+xml');
res.send(webfinger.genHostMeta(config.origin));
@@ -68,9 +68,9 @@ app.get('/_oauth/:user', function(req, res){
app.post(/^\/_oauth\/(?:(.+))/, function(req, res){
var token = "yo-ho"; //TODO generate proper token
- storage.createToken(req.param('userId'), req.param('password'), token, req.param('categories'), function(result) {
+ storage.createToken(req.param('userId'), req.param('password'), token, req.param('scope'), function(result) {
if(result) {
- res.redirect(redirectUri+'#access_token='+token);
+ res.redirect(req.param('redirectUri')+'#access_token='+token);
} else {
res.send("No, bro.", 401);
}
@@ -98,13 +98,28 @@ app.all('/:user/:category/:key', function(req, res){
userId: req.params.user,
category: req.params.category,
key: req.params.key,
- value: req.body
+ value: ''
};
- console.log(reqObj);
- doReq(reqObj, function(status_code, data) {
- res.send(data, status_code);
- });
+ if (req.method == "PUT") {
+ req.on('data', function(chunk) {
+ reqObj.value += chunk;
+ });
+ req.on('end', function() {
+ console.log(reqObj);
+
+ storage.doReq(reqObj, function(status_code, data) {
+ res.send(data, status_code);
+ });
+ });
+ }
+ else {
+ console.log(reqObj);
+
+ storage.doReq(reqObj, function(status_code, data) {
+ res.send(data, status_code);
+ });
+ }
}
catch (e) {
res.send(e, 500);
@@ -113,10 +128,10 @@ app.all('/:user/:category/:key', function(req, res){
});
if (!module.parent) {
- app.listen(4000);
+ app.listen(80);
console.log("Express server listening on port %d", app.address().port);
- storage.addUser('jimmy@surf.unhosted.org', '12345678', function() {
+ storage.addUser('jimmy@localhost', '12345678', function() {
console.log('created user jimmy@surf.unhosted.org with password 12345678');
});
}

0 comments on commit ed3883f

Please sign in to comment.
Something went wrong with that request. Please try again.