mirror of
https://github.com/fergalmoran/dss.web.git
synced 2026-02-15 12:34:17 +00:00
Fixed new API route
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
'use strict';
|
||||
var errors = require('./components/errors');
|
||||
var http = require('http');
|
||||
var url = require('url');
|
||||
function _parseUrl(u){
|
||||
var parts = url.parse(u, true, true);
|
||||
|
||||
var path = parts.pathname.split('/').filter(function(arg){
|
||||
return arg;
|
||||
});
|
||||
if (path.length == 2){
|
||||
//probably a mix, reconstruct url and return
|
||||
return parts.protocol + "//" + parts.host + "/mix/" + path[1];
|
||||
}
|
||||
return u;
|
||||
}
|
||||
module.exports = function (app) {
|
||||
|
||||
app.route('/config')
|
||||
@@ -21,7 +33,7 @@ module.exports = function (app) {
|
||||
app.route('/*')
|
||||
.get(function (req, res) {
|
||||
if (req.headers['user-agent'].indexOf('facebookexternalhit') > -1) {
|
||||
var url = (app.get('apiUrl') + req.path + '/').replace(/([^:]\/)\/+/g, "$1");
|
||||
var url = _parseUrl((app.get('apiUrl') + req.path + '/').replace(/([^:]\/)\/+/g, "$1"));
|
||||
console.log('Api url: ' + url);
|
||||
http.get(url, function (api_res) {
|
||||
var body = '';
|
||||
@@ -29,7 +41,7 @@ module.exports = function (app) {
|
||||
body += chunk;
|
||||
});
|
||||
api_res.on('end', function() {
|
||||
res.render('social/facebook/mix', JSON.parse(body));
|
||||
res.render('social/facebook/mix', JSON.parse(body));
|
||||
});
|
||||
}).on('error', function (e) {
|
||||
console.log("Got error: " + e.message);
|
||||
|
||||
Reference in New Issue
Block a user