From b738961e1cd4f905a04850baaabf589b2bbe506f Mon Sep 17 00:00:00 2001 From: Clint Brown Date: Sun, 20 Aug 2017 23:29:03 +1000 Subject: [PATCH 1/6] Fix paths when using TALK_ROOT_URL_MOUNT_PATH --- app.js | 14 +------------- .../talk-plugin-moderation/ModerationLink.js | 3 ++- graph/subscriptions.js | 4 +++- url.js | 19 +++++++++++++++++++ views/article.ejs | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 url.js diff --git a/app.js b/app.js index 9abb921ae..741dac93f 100644 --- a/app.js +++ b/app.js @@ -5,10 +5,9 @@ const path = require('path'); const helmet = require('helmet'); const compression = require('compression'); const cookieParser = require('cookie-parser'); -const {ROOT_URL, ROOT_URL_MOUNT_PATH} = require('./config'); +const {BASE_URL, BASE_PATH, MOUNT_PATH} = require('./url'); const routes = require('./routes'); const debug = require('debug')('talk:app'); -const {URL} = require('url'); const app = express(); @@ -51,17 +50,6 @@ app.set('view engine', 'ejs'); // ROUTES //============================================================================== -// Set the BASE_URL as the ROOT_URL, here we derive the root url by ensuring -// that it ends in a `/`. -const BASE_URL = ROOT_URL && ROOT_URL.length > 0 && ROOT_URL[ROOT_URL.length - 1] === '/' ? ROOT_URL : `${ROOT_URL}/`; - -// The BASE_PATH is simply the path component of the BASE_URL. -const BASE_PATH = new URL(BASE_URL).pathname; - -// The MOUNT_PATH is derived from the BASE_PATH, if it is provided and enabled. -// This will mount all the application routes onto it. -const MOUNT_PATH = ROOT_URL_MOUNT_PATH ? BASE_PATH : '/'; - // Apply the BASE_PATH, BASE_URL, and MOUNT_PATH on the app.locals, which will // make them available on the templates and the routers. app.locals.BASE_URL = BASE_URL; diff --git a/client/talk-plugin-moderation/ModerationLink.js b/client/talk-plugin-moderation/ModerationLink.js index 020b8c345..1a10160ee 100644 --- a/client/talk-plugin-moderation/ModerationLink.js +++ b/client/talk-plugin-moderation/ModerationLink.js @@ -2,10 +2,11 @@ import React, {PropTypes} from 'react'; import styles from './styles.css'; import t from 'coral-framework/services/i18n'; +import {BASE_PATH} from 'coral-framework/constants/url'; const ModerationLink = (props) => props.isAdmin ? (
- + {t('moderate_this_stream')}
diff --git a/graph/subscriptions.js b/graph/subscriptions.js index adac849e0..91ab3c091 100644 --- a/graph/subscriptions.js +++ b/graph/subscriptions.js @@ -26,6 +26,8 @@ const { SUBSCRIBE_ALL_USERNAME_REJECTED, } = require('../perms/constants'); +const {BASE_PATH} = require('../url'); + /** * Plugin support requires that we merge in existing setupFunctions with our new * plugin based ones. This allows plugins to extend existing setupFunctions as well @@ -172,7 +174,7 @@ const createSubscriptionManager = (server) => new SubscriptionServer({ keepAlive: ms(KEEP_ALIVE) }, { server, - path: '/api/v1/live' + path: '${BASE_PATH}api/v1/live' }); module.exports = { diff --git a/url.js b/url.js new file mode 100644 index 000000000..b39a9ab35 --- /dev/null +++ b/url.js @@ -0,0 +1,19 @@ +const {ROOT_URL, ROOT_URL_MOUNT_PATH} = require('./config'); +const {URL} = require('url'); + +// Set the BASE_URL as the ROOT_URL, here we derive the root url by ensuring +// that it ends in a `/`. +const BASE_URL = ROOT_URL && ROOT_URL.length > 0 && ROOT_URL[ROOT_URL.length - 1] === '/' ? ROOT_URL : `${ROOT_URL}/`; + +// The BASE_PATH is simply the path component of the BASE_URL. +const BASE_PATH = new URL(BASE_URL).pathname; + +// The MOUNT_PATH is derived from the BASE_PATH, if it is provided and enabled. +// This will mount all the application routes onto it. +const MOUNT_PATH = ROOT_URL_MOUNT_PATH ? BASE_PATH : '/'; + +module.exports = { + BASE_URL: BASE_URL, + BASE_PATH: BASE_PATH, + MOUNT_PATH: MOUNT_PATH, +} diff --git a/views/article.ejs b/views/article.ejs index f0a3dad98..0f8c75594 100644 --- a/views/article.ejs +++ b/views/article.ejs @@ -22,7 +22,7 @@

<%= title %>

<%= body %>

-

Admin - All Assets

+

Admin - All Assets