Skip to content

Commit

Permalink
Support running application in subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed May 31, 2024
1 parent 7a6fa82 commit 4167cce
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 39 deletions.
2 changes: 1 addition & 1 deletion client/views/add/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});

Expand Down
2 changes: 1 addition & 1 deletion client/views/answers/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Template.answers.helpers({
answers[a].text = answers[a].text.replace(/\B(@\S+)/g, '<strong>$1</strong>');
const urlRegex = new RegExp(SimpleSchema.RegEx.Url.source.slice(1, -1), 'ig');
answers[a].text = answers[a].text.replace(urlRegex, url =>
'<a target="_blank" class="questionLink" rel="nofollow" href="' + url + '">' + url + '</a>');
'<a target="_blank" class="questionLink" rel="nofollow" href="' + Meteor.absoluteUrl() + url + '">' + Meteor.absoluteUrl() + url + '</a>');
}

return answers;
Expand Down
2 changes: 1 addition & 1 deletion client/views/combine/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion client/views/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion client/views/delete/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion client/views/edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion client/views/forgotPassword/forgotPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}});
}
Expand Down
2 changes: 1 addition & 1 deletion client/views/helpers/chunks/instance_div/instance_div.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<span class="favebtn {{#if isFavorite}}unfavoritebutton{{else}}favoritebutton{{/if}}" id="{{_id}}" title="{{#if isFavorite}}Remove from favorites{{else}}Add to favorites{{/if}}"><i class="fa fa-{{#if isFavorite}}heart{{else}}heart-o{{/if}}"></i></span>
</div>
{{/if}}
<a href="/list/{{slug}}" title="Open instance">
<a href="{{ absolute_url }}list/{{slug}}" title="Open instance">
<p class="instancename">
{{tablename}}
</p>
Expand Down
3 changes: 3 additions & 0 deletions client/views/helpers/chunks/instance_div/instance_div.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ Template.instance_div.helpers({
date_format(lasttouch) {
return moment(lasttouch).format('LLL');
},
absolute_url() {
return Meteor.absoluteUrl();
},
});
4 changes: 2 additions & 2 deletions client/views/helpers/form_error/form_error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template name="form_error">
<div class="error">
<img src="/error.png" class="errorIcon">
<img src="{{ absolute_url }}error.png" class="errorIcon">
{{this}}
<span class="error-dismiss"><i class="fa fa-close"></i></span>
</div>
</template>
</template>
4 changes: 2 additions & 2 deletions client/views/helpers/nav/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions client/views/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,15 @@ 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;
let questionText = questionDiv.getElementsByClassName('questiontext')[0].innerHTML.trim();
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) {
Expand Down
19 changes: 19 additions & 0 deletions client/views/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion client/views/modify/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion client/views/pages/loading/loading.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="loading">
{{> nav list=true}}
<img src="/loading.gif" id="loadingSpinner">
<img src="{{ absolute_url }}loading.gif" id="loadingSpinner">
<h1 id="loadingText">Loading...</h1>
</template>
4 changes: 2 additions & 2 deletions client/views/pages/not_found/not_found.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template name="not_found">
<h1 id="notfoundheader">404 Not Found</h1>
<p id="notfoundmessage">Click <a id="notfoundlink" href="/">here</a> to return home.</p>
</template>
<p id="notfoundmessage">Click <a id="notfoundlink" href="{{ absolute_url }}">here</a> to return home.</p>
</template>
2 changes: 1 addition & 1 deletion client/views/rename/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion client/views/resetPassword/resetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion client/views/share/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
});

Expand Down
38 changes: 20 additions & 18 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
/* 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();
},
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 {
Expand All @@ -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 });
Expand All @@ -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 });
Expand All @@ -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 = {
Expand All @@ -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),
Expand All @@ -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;
Expand All @@ -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 });
Expand All @@ -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
Expand Down Expand Up @@ -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')
});

0 comments on commit 4167cce

Please sign in to comment.