From f08067bab266cee48adf2cb1a9386c95c0939317 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 29 Sep 2013 13:47:27 -0400 Subject: [PATCH] fixes #356 - issue where accessing a NodeBB using a different machine name from one that it was set up with causing template data to not load, as it was being accessed via absolute url, instead of relative url --- public/src/ajaxify.js | 4 ++-- public/src/app.js | 6 +----- public/src/templates.js | 14 ++++---------- public/templates/admin/testing/categories.tpl | 2 +- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 95619b4ffb..497823e3c7 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -38,8 +38,8 @@ var ajaxify = {}; window.onscroll = null; // end - - var url = url.replace(/\/$/, ""); + // Remove trailing slash + url = url.replace(/\/$/, ""); var hash = window.location.hash; diff --git a/public/src/app.js b/public/src/app.js index e0acf14152..5b9918afed 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -1,8 +1,6 @@ var socket, config, - app = {}, - API_URL = null; - + app = {}; (function () { var showWelcomeMessage = false; @@ -12,8 +10,6 @@ var socket, $.ajax({ url: RELATIVE_PATH + '/api/config', success: function (data) { - API_URL = data.api_url; - config = data; if(socket) { socket.disconnect(); diff --git a/public/src/templates.js b/public/src/templates.js index 25ed9a5d94..2e4faffc21 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -114,13 +114,9 @@ templates.load_template = function (callback, url, template) { var location = document.location || window.location, - rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''); - - var api_url = (url === '' || url === '/') ? 'home' : url; - - var tpl_url = templates.get_custom_map(api_url.split('?')[0]); - - var trimmed = api_url; + api_url = (url === '' || url === '/') ? 'home' : url, + tpl_url = templates.get_custom_map(api_url.split('?')[0]), + trimmed = api_url; if (!tpl_url) { tpl_url = templates.getTemplateNameFromUrl(api_url); @@ -128,7 +124,6 @@ var template_data = null; - (function () { var timestamp = new Date().getTime(); //debug @@ -155,8 +150,7 @@ }()); (function () { - - jQuery.get(API_URL + api_url, function (data) { + jQuery.get(RELATIVE_PATH + '/api/' + api_url, function (data) { if (!data) { ajaxify.go('404'); diff --git a/public/templates/admin/testing/categories.tpl b/public/templates/admin/testing/categories.tpl index 5bab8d5857..1b2709d1fb 100644 --- a/public/templates/admin/testing/categories.tpl +++ b/public/templates/admin/testing/categories.tpl @@ -10,7 +10,7 @@ jQuery(document).ready(function () { QUnit.init(); asyncTest( "Loading Categories", function() { - jQuery.get(config.api_url + 'home', function(data) { + jQuery.get(RELATIVE_PATH + '/api/home', function(data) { ok( data.categories.length > 0, JSON.stringify(data.categories) ); start();