From e3b129f5290437875eddcdc84cd309bd0c6b42d1 Mon Sep 17 00:00:00 2001
From: joaofranciscosantos <joao.francis.santos@gmail.com>
Date: Sat, 21 Mar 2020 15:53:11 +0100
Subject: [PATCH] Fix trailing slash for windows os

---
 packages/react-dev-utils/redirectServedPathMiddleware.js | 2 +-
 packages/react-scripts/config/webpack.config.js          | 4 +++-
 packages/react-scripts/config/webpackDevServer.config.js | 3 ++-
 packages/react-scripts/scripts/start.js                  | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/packages/react-dev-utils/redirectServedPathMiddleware.js b/packages/react-dev-utils/redirectServedPathMiddleware.js
index a71578f0a..e53760539 100644
--- a/packages/react-dev-utils/redirectServedPathMiddleware.js
+++ b/packages/react-dev-utils/redirectServedPathMiddleware.js
@@ -10,7 +10,7 @@ const path = require('path');
 
 module.exports = function createRedirectServedPathMiddleware(servedPath) {
   // remove end slash so user can land on `/test` instead of `/test/`
-  servedPath = servedPath.slice(0, -1);
+  servedPath = servedPath.endsWith(path.sep) ? servedPath.slice(0, -1) : servedPath
   return function redirectServedPathMiddleware(req, res, next) {
     if (
       servedPath === '' ||
diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js
index 25840d911..c24e4b16c 100644
--- a/packages/react-scripts/config/webpack.config.js
+++ b/packages/react-scripts/config/webpack.config.js
@@ -75,7 +75,9 @@ module.exports = function(webpackEnv) {
   // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
   // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
   // Get environment variables to inject into our app.
-  const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
+  const env = getClientEnvironment(
+  paths.publicUrlOrPath.endsWith(path.sep) ? paths.publicUrlOrPath.slice(0, -1) : paths.publicUrlOrPath
+  );
 
   // common function to get style loaders
   const getStyleLoaders = (cssOptions, preProcessor) => {
diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js
index bd91927da..fc37ac8fd 100644
--- a/packages/react-scripts/config/webpackDevServer.config.js
+++ b/packages/react-scripts/config/webpackDevServer.config.js
@@ -9,6 +9,7 @@
 'use strict';
 
 const fs = require('fs');
+const path = require('path');
 const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
 const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
 const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
@@ -87,7 +88,7 @@ module.exports = function(proxy, allowedHost) {
     // we specified in the webpack config. When homepage is '.', default to serving
     // from the root.
     // remove last slash so user can land on `/test` instead of `/test/`
-    publicPath: paths.publicUrlOrPath.slice(0, -1),
+    publicPath: paths.publicUrlOrPath.endsWith(path.sep) ? paths.publicUrlOrPath.slice(0, -1) : paths.publicUrlOrPath,
     // WebpackDevServer is noisy by default so we emit custom message instead
     // by listening to the compiler events with `compiler.hooks[...].tap` calls above.
     quiet: true,
diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js
index 2568ab36d..a1330d1c3 100644
--- a/packages/react-scripts/scripts/start.js
+++ b/packages/react-scripts/scripts/start.js
@@ -32,6 +32,7 @@ verifyTypeScriptSetup();
 // @remove-on-eject-end
 
 const fs = require('fs');
+const path = require('path');
 const chalk = require('react-dev-utils/chalk');
 const webpack = require('webpack');
 const WebpackDevServer = require('webpack-dev-server');
@@ -101,7 +102,7 @@ checkBrowsers(paths.appPath, isInteractive)
       protocol,
       HOST,
       port,
-      paths.publicUrlOrPath.slice(0, -1)
+      paths.publicUrlOrPath.endsWith(path.sep) ? paths.publicUrlOrPath.slice(0, -1) : paths.publicUrlOrPath
     );
     const devSocket = {
       warnings: warnings =>
-- 
GitLab