From 0e1948cd3a6d3b9b60399381849e4492cba16b54 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 13 Aug 2015 12:58:59 +0930 Subject: [PATCH] Support running in subdirectory with base_path config --- framework/core/js/forum/src/initializers/boot.js | 7 ++++++- framework/core/js/lib/App.js | 3 ++- framework/core/js/lib/utils/mapRoutes.js | 5 +++-- framework/core/less/lib/lib.less | 2 +- framework/core/src/Api/Serializers/ForumSerializer.php | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/framework/core/js/forum/src/initializers/boot.js b/framework/core/js/forum/src/initializers/boot.js index 3b75a0232..3ba967930 100644 --- a/framework/core/js/forum/src/initializers/boot.js +++ b/framework/core/js/forum/src/initializers/boot.js @@ -45,8 +45,13 @@ export default function boot(app) { app.modal = m.mount(document.getElementById('modal'), ModalManager.component()); app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component()); + const basePath = app.forum.attribute('basePath'); m.route.mode = 'pathname'; - m.route(document.getElementById('content'), '/', mapRoutes(app.routes)); + m.route( + document.getElementById('content'), + basePath + '/', + mapRoutes(app.routes, basePath) + ); m.endComputation(); diff --git a/framework/core/js/lib/App.js b/framework/core/js/lib/App.js index c8327efdd..0954b2016 100644 --- a/framework/core/js/lib/App.js +++ b/framework/core/js/lib/App.js @@ -254,8 +254,9 @@ export default class App { route(name, params = {}) { const url = this.routes[name].path.replace(/:([^\/]+)/g, (m, key) => extract(params, key)); const queryString = m.route.buildQueryString(params); + const prefix = m.route.mode === 'pathname' ? app.forum.attribute('basePath') : ''; - return url + (queryString ? '?' + queryString : ''); + return prefix + url + (queryString ? '?' + queryString : ''); } /** diff --git a/framework/core/js/lib/utils/mapRoutes.js b/framework/core/js/lib/utils/mapRoutes.js index 879e318bb..0ebebce15 100644 --- a/framework/core/js/lib/utils/mapRoutes.js +++ b/framework/core/js/lib/utils/mapRoutes.js @@ -4,9 +4,10 @@ * * @see https://lhorie.github.io/mithril/mithril.route.html#defining-routes * @param {Object} routes + * @param {String} [basePath] * @return {Object} */ -export default function mapRoutes(routes) { +export default function mapRoutes(routes, basePath = '') { const map = {}; for (const key in routes) { @@ -14,7 +15,7 @@ export default function mapRoutes(routes) { if (route.component) route.component.props.routeName = key; - map[route.path] = route.component; + map[basePath + route.path] = route.component; } return map; diff --git a/framework/core/less/lib/lib.less b/framework/core/less/lib/lib.less index cb6f59ea8..2ad890939 100755 --- a/framework/core/less/lib/lib.less +++ b/framework/core/less/lib/lib.less @@ -1,7 +1,7 @@ @import url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,600); @import "font-awesome.less"; -@fa-font-path: "/assets/fonts"; +@fa-font-path: "../../assets/fonts"; @import "normalize.less"; @import "print.less"; diff --git a/framework/core/src/Api/Serializers/ForumSerializer.php b/framework/core/src/Api/Serializers/ForumSerializer.php index 3b13c201e..567f97f38 100644 --- a/framework/core/src/Api/Serializers/ForumSerializer.php +++ b/framework/core/src/Api/Serializers/ForumSerializer.php @@ -25,6 +25,7 @@ class ForumSerializer extends Serializer $attributes = [ 'title' => Core::config('forum_title'), 'baseUrl' => Core::config('base_url'), + 'basePath' => Core::config('base_path'), 'apiUrl' => Core::config('api_url'), 'welcomeTitle' => Core::config('welcome_title'), 'welcomeMessage' => Core::config('welcome_message'),