diff --git a/client/views/add/add.js b/client/views/add/add.js index 4e25584a..dde05a3b 100644 --- a/client/views/add/add.js +++ b/client/views/add/add.js @@ -20,7 +20,7 @@ function checkPrevMod(modBoxes) { Template.add.onCreated(function () { this.numberOfNewMods = new ReactiveVar(1); if (this.data.admin !== Meteor.user().emails[0].address) { - Router.go('/'); + Router.go(Meteor.absoluteUrl()); } }); diff --git a/client/views/answers/answers.js b/client/views/answers/answers.js index 1487bffa..26f9a5d6 100644 --- a/client/views/answers/answers.js +++ b/client/views/answers/answers.js @@ -29,7 +29,7 @@ Template.answers.helpers({ answers[a].text = answers[a].text.replace(/\B(@\S+)/g, '$1'); const urlRegex = new RegExp(SimpleSchema.RegEx.Url.source.slice(1, -1), 'ig'); answers[a].text = answers[a].text.replace(urlRegex, url => - '' + url + ''); + '' + Meteor.absoluteUrl() + url + ''); } return answers; diff --git a/client/views/combine/combine.js b/client/views/combine/combine.js index 358a1ac2..77932cc7 100644 --- a/client/views/combine/combine.js +++ b/client/views/combine/combine.js @@ -13,7 +13,7 @@ Template.combine.onCreated(function () { Meteor.call('adminCheck', this.data.instanceid, (e, r) => { if (!r) { // If not, redirects back to the list page - window.location.href = '/'; + window.location.href = Meteor.absoluteUrl(); } }); }); diff --git a/client/views/create/create.js b/client/views/create/create.js index 65218b2a..b554660f 100644 --- a/client/views/create/create.js +++ b/client/views/create/create.js @@ -133,7 +133,7 @@ Template.create.events({ $('#navCreate').html('+ Create'); document.getElementById('navCreate').style.backgroundColor = '#27ae60'; $('#toparea').slideUp(); - window.location.href = Iron.Location.get().originalUrl + 'list/' + result; + window.location.href = Meteor.absoluteUrl() + 'list/' + result; }); }, 'keypress #instancedescriptioninput': function (event, template) { diff --git a/client/views/delete/delete.js b/client/views/delete/delete.js index 01ac6429..ef40ff5a 100644 --- a/client/views/delete/delete.js +++ b/client/views/delete/delete.js @@ -24,7 +24,7 @@ Template.delete.events({ currentError = Blaze.renderWithData(Template.form_error, e, document.getElementsByClassName('deleteError')[0]); } else { removePopover(); - Router.go('/'); + Router.go(Meteor.absoluteUrl()); } }); }, diff --git a/client/views/edit/edit.js b/client/views/edit/edit.js index 3f4b7df4..5d8c655f 100644 --- a/client/views/edit/edit.js +++ b/client/views/edit/edit.js @@ -60,7 +60,7 @@ Template.edit.events({ } else { const isList = template.data.isList; if (isList) { - window.location.href = '/list/' + Instances.findOne({ _id: table._id }).slug; + window.location.href = Meteor.absoluteUrl() + 'list/' + Instances.findOne({ _id: table._id }).slug; } else { Blaze.remove(popoverTemplate); } diff --git a/client/views/forgotPassword/forgotPassword.js b/client/views/forgotPassword/forgotPassword.js index 9146d578..7f6fd87a 100644 --- a/client/views/forgotPassword/forgotPassword.js +++ b/client/views/forgotPassword/forgotPassword.js @@ -40,7 +40,7 @@ Template.ForgotPassword.events({ $('.formcontainer').fadeOut(400); $('#darker').fadeOut(400); var sAlertId = sAlert.success('Email sent, check your mailbox', {timeout: 4000, position: 'top-right', onClose: function() { - window.location.href = '/'; + window.location.href = Meteor.absoluteUrl(); sAlert.close(sAlertId); }}); } diff --git a/client/views/helpers/chunks/instance_div/instance_div.html b/client/views/helpers/chunks/instance_div/instance_div.html index 28ea7967..324f30e7 100644 --- a/client/views/helpers/chunks/instance_div/instance_div.html +++ b/client/views/helpers/chunks/instance_div/instance_div.html @@ -17,7 +17,7 @@ {{/if}} - +

{{tablename}}

diff --git a/client/views/helpers/chunks/instance_div/instance_div.js b/client/views/helpers/chunks/instance_div/instance_div.js index eae1499d..e257bb50 100644 --- a/client/views/helpers/chunks/instance_div/instance_div.js +++ b/client/views/helpers/chunks/instance_div/instance_div.js @@ -11,4 +11,7 @@ Template.instance_div.helpers({ date_format(lasttouch) { return moment(lasttouch).format('LLL'); }, + absolute_url() { + return Meteor.absoluteUrl(); + }, }); diff --git a/client/views/helpers/form_error/form_error.html b/client/views/helpers/form_error/form_error.html index 5c17c5c5..e82b23c3 100644 --- a/client/views/helpers/form_error/form_error.html +++ b/client/views/helpers/form_error/form_error.html @@ -1,7 +1,7 @@ \ No newline at end of file + diff --git a/client/views/helpers/nav/nav.js b/client/views/helpers/nav/nav.js index 9cf8a4b2..75566566 100644 --- a/client/views/helpers/nav/nav.js +++ b/client/views/helpers/nav/nav.js @@ -27,7 +27,7 @@ Template.nav.events({ 'click #navHome': function (event, template) { document.getElementById('searchbar').value = ''; Session.set('search', ''); - Router.go('/'); + Router.go(Meteor.absoluteUrl()); }, 'click #darker': function (event, template) { $('.formcontainer').fadeOut(400); @@ -38,7 +38,7 @@ Template.nav.events({ 'click #navCode': function(event, template) { const parentNode = document.getElementById('nav'); popoverTemplate = Blaze.renderWithData(Template.qr_code, { - link: Meteor.absoluteUrl() + `/list/${template.data.slug}` + link: Meteor.absoluteUrl() + `list/${template.data.slug}` }, parentNode); }, 'click #navArchive': function(event, template) { diff --git a/client/views/list/list.js b/client/views/list/list.js index bab5730f..ef840aae 100644 --- a/client/views/list/list.js +++ b/client/views/list/list.js @@ -638,7 +638,7 @@ Template.list.events({ // return Users.find({name: {$regex: re}}); }, 'click .facebookbutton': function (event, template) { - popupwindow('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.origin + '/list/' + template.data.slug), 'Share Question Tool!', 600, 400); + popupwindow('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(Meteor.absoluteUrl() + 'list/' + template.data.slug), 'Share Question Tool!', 600, 400); }, 'click .twitterbutton': function (event, template) { const questionDiv = event.target.parentElement.parentElement.parentElement; @@ -646,7 +646,7 @@ Template.list.events({ if (questionText.length > 35) { questionText = questionText.substring(0, 34); } - const tweetText = 'Check out this question: "' + questionText + '..." on Question Tool by @berkmancenter ' + window.location.origin + '/list/' + template.data.slug; + const tweetText = 'Check out this question: "' + questionText + '..." on Question Tool by @berkmancenter ' + Meteor.absoluteUrl() + 'list/' + template.data.slug; popupwindow('https://twitter.com/intent/tweet?text=' + encodeURIComponent(tweetText), 'Share Question Tool!', 600, 400); }, 'click #modbutton': function (event, template) { diff --git a/client/views/main/main.js b/client/views/main/main.js index c0fb5be1..8025eb06 100644 --- a/client/views/main/main.js +++ b/client/views/main/main.js @@ -216,4 +216,23 @@ Template.home.events({ event.stopPropagation(); }, }); + +Template.not_found.helpers({ + absolute_url() { + return Meteor.absoluteUrl(); + }, +}); + +Template.loading.helpers({ + absolute_url() { + return Meteor.absoluteUrl(); + }, +}); + +Template.form_error.helpers({ + absolute_url() { + return Meteor.absoluteUrl(); + }, +}); + /* eslint-enable func-names, no-unused-vars */ diff --git a/client/views/modify/modify.js b/client/views/modify/modify.js index 1d4c71d2..a0a39f54 100644 --- a/client/views/modify/modify.js +++ b/client/views/modify/modify.js @@ -16,7 +16,7 @@ Template.modify.onCreated(() => { // If not, redirects back to the list page const instanceid = Questions.findOne({ _id: quest }).instanceid; const slug = Instances.findOne({ _id: instanceid }).slug; - window.location.href = '/list/' + slug; + window.location.href = Meteor.absoluteUrl() + 'list/' + slug; } }); }); diff --git a/client/views/pages/loading/loading.html b/client/views/pages/loading/loading.html index c5935e63..53f5ec8c 100644 --- a/client/views/pages/loading/loading.html +++ b/client/views/pages/loading/loading.html @@ -1,5 +1,5 @@ diff --git a/client/views/pages/not_found/not_found.html b/client/views/pages/not_found/not_found.html index d66d2fef..32ccda34 100644 --- a/client/views/pages/not_found/not_found.html +++ b/client/views/pages/not_found/not_found.html @@ -1,4 +1,4 @@ \ No newline at end of file +

Click here to return home.

+ diff --git a/client/views/rename/rename.js b/client/views/rename/rename.js index 916ec7fd..d66f7be0 100644 --- a/client/views/rename/rename.js +++ b/client/views/rename/rename.js @@ -33,7 +33,7 @@ Template.rename.events({ } else if (result) { const isList = template.data.isList; if (isList) { - window.location.href = '/list/' + Instances.findOne({ _id: table._id }).slug; + window.location.href = Meteor.absoluteUrl() + 'list/' + Instances.findOne({ _id: table._id }).slug; } else { Blaze.remove(popoverTemplate); } diff --git a/client/views/resetPassword/resetPassword.js b/client/views/resetPassword/resetPassword.js index c7aa2bd2..5aa846e5 100644 --- a/client/views/resetPassword/resetPassword.js +++ b/client/views/resetPassword/resetPassword.js @@ -29,7 +29,7 @@ Template.ResetPassword.events({ showError('Something went wrong', 'inputcontainer', 'resetPassword'); } else { console.log('Password has been changed'); - window.location.href = '/'; + window.location.href = Meteor.absoluteUrl(); } }); } diff --git a/client/views/share/share.js b/client/views/share/share.js index 466b3567..3a1ab938 100644 --- a/client/views/share/share.js +++ b/client/views/share/share.js @@ -5,7 +5,7 @@ Template.share.onRendered(() => { Template.share.helpers({ shareLink() { - return window.location.origin + '/list/' + Template.instance().data; + return Meteor.absoluteUrl() + 'list/' + Template.instance().data; }, }); diff --git a/lib/routes.js b/lib/routes.js index 71a9e97c..c883716a 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -1,13 +1,15 @@ /* eslint-disable func-names */ import { Instances, Questions, Answers } from './common.js'; +const urlPathPrefix = Meteor.settings.public.urlPathPrefix || '' + Router.configure({ notFoundTemplate: 'not_found', loadingTemplate: 'loading', }); Router.route('home', { - path: '/', + path: '/' + urlPathPrefix, template: 'home', data() { return Instances.find({ hidden: { $ne: true } }).fetch(); @@ -15,15 +17,15 @@ Router.route('home', { fastRender: true, }); -Router.route('/credits', function () { +Router.route(urlPathPrefix + '/credits', function () { this.render('credits'); }); -Router.route('/dashboard', function () { +Router.route(urlPathPrefix + '/dashboard', function () { this.render('dashboard'); }); -Router.route('/create', function () { +Router.route(urlPathPrefix + '/create', function () { if (Meteor.user()) { this.render('create'); } else { @@ -33,33 +35,33 @@ Router.route('/create', function () { } }); -Router.route('/admin', function () { +Router.route(urlPathPrefix + '/admin', function () { this.render('admin'); }); -Router.route('/propose', function () { +Router.route(urlPathPrefix + '/propose', function () { this.render('propose'); }); -Router.route('/report', function () { +Router.route(urlPathPrefix + '/report', function () { this.render('report'); }); -Router.route('/login', function () { +Router.route(urlPathPrefix + '/login', function () { this.render('login'); }); -Router.route('/delete', function () { +Router.route(urlPathPrefix + '/delete', function () { this.render('delete'); }); -Router.route('/add', function () { +Router.route(urlPathPrefix + '/add', function () { this.render('add'); }); // When the user visits /answer/id, display answer template with question data Router.route('answer', { - path: '/answer/:_id', + path: urlPathPrefix + '/answer/:_id', template: 'answer', data() { const question = Questions.findOne({ _id: this.params._id }); @@ -69,7 +71,7 @@ Router.route('answer', { // When the user visits /modify/id, display modify template with question data Router.route('modify', { - path: '/modify/:_id', + path: urlPathPrefix + '/modify/:_id', template: 'modify', data() { const question = Questions.findOne({ _id: this.params._id }); @@ -79,7 +81,7 @@ Router.route('modify', { // When the user visits //id1/id2, display template with data for both questions 1 and 2 Router.route('', { - path: '//:first/:second', + path: urlPathPrefix + '//:first/:second', template: '', data() { const questionData = { @@ -92,7 +94,7 @@ Router.route('', { // When the user visits /list/tablename, set cookie to tablename and display list Router.route('listlink', { - path: '/list/:slug', + path: urlPathPrefix + '/list/:slug', waitOn() { return [ Meteor.subscribe('questions', this.params.slug), @@ -116,7 +118,7 @@ Router.route('listlink', { }, }); -Router.route('/list/:slug/touch', +Router.route(urlPathPrefix + '/list/:slug/touch', { onBeforeAction() { const instanceId = Instances.findOne({ slug: this.params.slug })._id; @@ -140,7 +142,7 @@ Router.route('/list/:slug/touch', // When the user visits /rename/id, display rename template with instance data Router.route('rename', { - path: '/rename/:_id', + path: urlPathPrefix + '/rename/:_id', template: 'rename', data() { const instance = Instances.findOne({ _id: this.params._id }); @@ -149,7 +151,7 @@ Router.route('rename', { }); // When the user visits rss/tablename, create an RSS file using table data -Router.route('/rss/:tablename', { +Router.route(urlPathPrefix + '/rss/:tablename', { where: 'server', action() { // Retrieves table and question data for the tablename parameter @@ -203,6 +205,6 @@ Router.route('/rss/:tablename', { }); // When the user visits the reset password -Router.route('/reset-password/:token', function() { +Router.route(urlPathPrefix + '/reset-password/:token', function() { this.render('ResetPassword') });