diff --git a/build/webpack/plugins.js b/build/webpack/plugins.js index c674012c47a9..54fdb3ffc50a 100644 --- a/build/webpack/plugins.js +++ b/build/webpack/plugins.js @@ -5,7 +5,6 @@ const SWPrecachedWebpackPlugin = require('sw-precache-webpack-plugin'); const webpack = require('webpack'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const PATHS = require('./paths'); -const languages = require('../../scripts/common').languages; const getPlugins = (app, grunt) => ([ new CircularDependencyPlugin({ @@ -25,12 +24,12 @@ const getPlugins = (app, grunt) => ([ fileName: 'asset-manifest.json', }), - ...(languages.map(lang => new SWPrecachedWebpackPlugin({ + new SWPrecachedWebpackPlugin({ cachedId : 'app', dontCacheBustUrlsMatching : /\.\w{8}\./, minify : false, navigateFallback : '', - filepath : path.resolve(PATHS.DIST, `${lang.toLowerCase()}/service-worker.js`), + filepath : path.resolve(PATHS.DIST, 'service-worker.js'), // TODO Uncomment below lines when changing the release process order to execute `js` task after `render` // staticFileGlobs : [ // path.resolve(PATHS.DIST, `${lang.toLowerCase()}/index.html`), @@ -46,7 +45,7 @@ const getPlugins = (app, grunt) => ([ // eslint-disable-next-line no-console console.log(message); }, - }))), + }), ] : [] ), diff --git a/scripts/common.js b/scripts/common.js index 25eb6c917b39..80f46615590e 100644 --- a/scripts/common.js +++ b/scripts/common.js @@ -22,7 +22,6 @@ exports.sections_config = { path : '', js_files : ['vendor', 'react_mobx', 'binary_common', 'binary'], css_files: ['app.min', 'smartcharts'], - has_pjax : false, }, }; diff --git a/src/javascript/app/App/app.jsx b/src/javascript/app/App/app.jsx index ac21a0506c3b..ce0c403c88f3 100644 --- a/src/javascript/app/App/app.jsx +++ b/src/javascript/app/App/app.jsx @@ -1,7 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; -import getBaseName from 'Utils/URL/base-name'; import { MobxProvider } from 'Stores/connect'; import ErrorBoundary from './Components/Elements/Errors/error-boundary.jsx'; import PushNotification from './Containers/push-notification.jsx'; @@ -19,7 +18,7 @@ import './i18n'; const isTouchDevice = 'ontouchstart' in document.documentElement; const App = ({ root_store }) => ( - + { root_store.ui.is_mobile || (root_store.ui.is_tablet && isTouchDevice) ? diff --git a/src/javascript/app/Utils/URL/__tests__/base-name.spec.js b/src/javascript/app/Utils/URL/__tests__/base-name.spec.js deleted file mode 100644 index 5c96b31641af..000000000000 --- a/src/javascript/app/Utils/URL/__tests__/base-name.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -import { expect } from 'chai'; -import getBaseName from '../base-name'; -import { websiteUrl } from '../../../../_common/url'; -import { setURL } from '../../../../_common/__tests__/tests_common'; - -describe('base_name.getBaseName', () => { - it('expect return correct value when pathname is not set', () => { - expect(getBaseName()).to.eq('/en'); - }); - it('expect return correct value when pathname is set', () => { - setURL(`${websiteUrl()}de/home.html`); - expect(getBaseName()).to.eq('/de'); - }); - after(() => { - setURL(`${websiteUrl()}en/home.html`); - }); -}); diff --git a/src/javascript/app/Utils/URL/base-name.js b/src/javascript/app/Utils/URL/base-name.js deleted file mode 100644 index cc1a6c4052ce..000000000000 --- a/src/javascript/app/Utils/URL/base-name.js +++ /dev/null @@ -1,19 +0,0 @@ -import { getAll as getAllLanguages } from '_common/language'; - -/* - * Retrieves basename from current url - * - * @return {string} returns the basename of current url - */ -const getBaseName = () => { - const regex_string = `(.*/(${Object.keys(getAllLanguages()).join('|')})(/index\\.html)?).*`; - const basename = new RegExp(regex_string, 'ig').exec(window.location.pathname); - - if (basename && basename.length) { - return basename[1]; - } - - return '/en/'; -}; - -export default getBaseName; diff --git a/src/root_files/_common/404.html b/src/root_files/_common/404.html index 1e99748089c4..45f95ebdf69f 100644 --- a/src/root_files/_common/404.html +++ b/src/root_files/_common/404.html @@ -42,29 +42,27 @@ function redirectToReactRoute(lang) { // Converts the path and query strings into just query strings and // then redirects the browser to the new url with query strings and hash fragment. - // https://deriv.app/en/statement -> https://deriv.app/en?p=/statement - + // https://deriv.app/reports/positions -> https://deriv.app/?p=reports::positions var pathname = location.pathname.toLowerCase().replace(/\/index(\.html)?/, ''); - var base = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : ''); - var regex = new RegExp('^((\/[A-Za-z0-9-_]+){0,2})(\/('+ all_languages.join('|') +'))((\/[A-Za-z0-9-_]+)+)', 'i'); - var result = regex.exec(pathname); - // Sensible defaults - var prefix = ''; - var default_lang = 'en'; - var routes = ''; - if (result && result.length) { - prefix = result[1] || ''; - default_lang = result[4].toLowerCase() || 'en'; - routes = result[5] ? result[5].substr(1).replace('/', '::') : ''; + var base = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : ''); + var br_regex = new RegExp('\/br_[A-Za-z0-9-_]+\/') + var result = br_regex.exec(pathname); + var pathname_has_br_path = result && result.length; + var br_branch_name = ''; + var routes; + if (pathname_has_br_path) { + br_branch_name = result[0].substring(0, result[0].length - 1); + routes = pathname.substring(br_branch_name.length); + } else { + routes = pathname; } - - var default_lang = 'EN'; // TODO remove this when i18n is ready. location.replace( base - + prefix // /br_branch_name + + br_branch_name // /br_branch_name + '/' // https://deriv.app/ - + default_lang.toLowerCase() + '?from_404=true&p=' // en?p= - + routes // statement + // + default_lang.toLowerCase() TODO: add language to querystring instead + + '?from_404=true&p=' // en?p= + + routes.substr(1).replace('/', '::') // statement + ( location.search ? '&q=' + location.search.slice(1).replace(/&/g, '~and~') : '' ) + location.hash