From f2ba57eca854ca1e859de9c5ae0543d21ecc30d4 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Tue, 22 Oct 2019 19:07:01 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20les=20redirections=20cot=C3=A9=20front?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vu qu'on utilise un serviceworker, lorsque la requête ne passe pas jusqu'au serveur, la redirection n'est pas effective On parse les règles de redirection netlify coté front et on les ajoute à l'app --- package.json | 1 + source/sites/mon-entreprise.fr/App.js | 5 ++++- source/sites/mon-entreprise.fr/redirects.js | 10 ++++++++++ source/webpack.common.js | 5 ++++- yarn.lock | 12 ++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 source/sites/mon-entreprise.fr/redirects.js diff --git a/package.json b/package.json index 8e58e84cf..2fe70fb95 100644 --- a/package.json +++ b/package.json @@ -158,6 +158,7 @@ "source-map-support": "^0.5.4", "style-loader": "^0.23.1", "styled-components": "^4.2.0", + "toml-loader": "^1.0.0", "url-loader": "^1.0.1", "webpack": "^4.39.3", "webpack-cli": "^3.1.2", diff --git a/source/sites/mon-entreprise.fr/App.js b/source/sites/mon-entreprise.fr/App.js index 9404f2c41..8206b63a5 100644 --- a/source/sites/mon-entreprise.fr/App.js +++ b/source/sites/mon-entreprise.fr/App.js @@ -8,7 +8,7 @@ import Raven from 'raven-js' import React, { useEffect } from 'react' import { Helmet } from 'react-helmet' import { useTranslation } from 'react-i18next' -import { Route, Switch } from 'react-router-dom' +import { Redirect, Route, Switch } from 'react-router-dom' import 'Ui/index.css' import Provider from '../../Provider' import { persistEverything, retrievePersistedState } from '../../storage/persistEverything' @@ -31,6 +31,7 @@ import Integration from './pages/integration/index' import Landing from './pages/Landing/Landing.js' import Simulateurs from './pages/Simulateurs' import ÉconomieCollaborative from './pages/ÉconomieCollaborative' +import redirects from './redirects' import { constructLocalizedSitePath } from './sitePaths' @@ -101,6 +102,8 @@ const App = compose(withSitePaths)(({ sitePaths }) => {
+ {redirects} + status === 301 && !from.startsWith('https')) + .map(x => console.log(x) || x) + .map(({ from, to }) => + + ) \ No newline at end of file diff --git a/source/webpack.common.js b/source/webpack.common.js index edd74dbc9..e2f9caa14 100644 --- a/source/webpack.common.js +++ b/source/webpack.common.js @@ -117,7 +117,10 @@ module.exports.commonLoaders = ({ legacy = false } = {}) => { test: /\.yaml$/, use: ['json-loader', 'yaml-loader'] }, - + { + test: /\.toml$/, + use: ['toml-loader'] + }, { test: /\.ne$/, use: [babelLoader, 'nearley-loader'] diff --git a/yarn.lock b/yarn.lock index 8e6857895..c6e797a10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10803,6 +10803,18 @@ toidentifier@1.0.0: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== +toml-loader@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/toml-loader/-/toml-loader-1.0.0.tgz#05249b9294b623601148260caa480b22a653a19a" + integrity sha1-BSSbkpS2I2ARSCYMqkgLIqZToZo= + dependencies: + toml "^2.2.2" + +toml@^2.2.2: + version "2.3.6" + resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.6.tgz#25b0866483a9722474895559088b436fd11f861b" + integrity sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ== + topo@2.x.x: version "2.0.2" resolved "https://registry.yarnpkg.com/topo/-/topo-2.0.2.tgz#cd5615752539057c0dc0491a621c3bc6fbe1d182"