From ca2673bdd3218d41e8b1bdadedd0c37d2abb7174 Mon Sep 17 00:00:00 2001
From: Yannis Barlas <yannisbarlas@gmail.com>
Date: Fri, 20 Nov 2020 13:02:17 +0200
Subject: [PATCH] fix(server): make 0.0.0.0 be set as localhost for CORS setup

---
 src/app.js | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/app.js b/src/app.js
index f05661e..960c7ff 100644
--- a/src/app.js
+++ b/src/app.js
@@ -59,9 +59,17 @@ const configureApp = app => {
   // Allow CORS from client if host / port is different
   if (config.has('pubsweet-client.host')) {
     const clientProtocol = config.get('pubsweet-client.protocol') || 'http'
-    const clientHost = config.get('pubsweet-client.host')
+    let clientHost = config.get('pubsweet-client.host')
     const clientPort = config.get('pubsweet-client.port')
 
+    // This is here because webpack dev server might need to be started with
+    // 0.0.0.0 instead of localhost, but the incoming request will still be
+    // eg. http://localhost:4000, not http://0.0.0.0:4000, which will make
+    // the CORS check fail
+    if (clientHost === '0.0.0.0' || clientHost === '127.0.0.1') {
+      clientHost = 'localhost'
+    }
+
     const clientUrl = `${clientProtocol}://${clientHost}${
       clientPort ? `:${clientPort}` : ''
     }`
-- 
GitLab