question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run with Relative Paths in development

See original GitHub issue

It is possible to build for Relative Paths.

How would I do the same when running in development using npm start?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kimhansecommented, Sep 28, 2017

Our workaround for the websocket issue is to have this in our nginx proxy config:

    location /v2/ {
      proxy_pass http://127.0.0.1:3000;
    }
    location /sockjs-node/ {
      proxy_pass http://127.0.0.1:3000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
1reaction
kimhansecommented, Sep 28, 2017

Our solution was to eject and then modify some of the generated config files. It appears that this is working except that the web socket is still placed under root dir, and we can live with that in dev.

The changes we had to do to the configuration to move our application from / to /v2/ was:

diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js
index 0047b70..e6ae8f9 100644
--- a/config/webpack.config.dev.js
+++ b/config/webpack.config.dev.js
@@ -14,11 +14,11 @@ const paths = require('./paths');
 
 // Webpack uses `publicPath` to determine where the app is being served from.
 // In development, we always serve from the root. This makes config easier.
-const publicPath = '/';
+const publicPath = '/v2/';
 // `publicUrl` is just like `publicPath`, but we will provide it to our app
 // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
 // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
-const publicUrl = '';
+const publicUrl = '/v2';
 // Get environment variables to inject into our app.
 const env = getClientEnvironment(publicUrl);
 
diff --git a/config/webpackDevServer.config.js b/config/webpackDevServer.config.js
index 0fb049d..211a2b8 100644
--- a/config/webpackDevServer.config.js
+++ b/config/webpackDevServer.config.js
@@ -75,6 +75,7 @@ module.exports = function(proxy, allowedHost) {
       // Paths with dots should still use the history fallback.
       // See https://github.com/facebookincubator/create-react-app/issues/387.
       disableDotRule: true,
+      index: '/v2/',
     },
     public: allowedHost,
     proxy,
diff --git a/package.json b/package.json
index 947a951..c559e00 100644
--- a/package.json
+++ b/package.json
@@ -2,6 +2,7 @@
   "name": "webapp2",
   "version": "0.1.0",
   "private": true,
+  "homepage": "/v2",
   "dependencies": {
     "autoprefixer": "7.1.2",
     "axios": "^0.16.2",
Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple trick to work with relative paths in Python | by Mike Huls
Simple trick to work with relative paths in Python. Calculate the file path at runtime with ease. Let's calculate the path to ...
Read more >
Understanding Relative File Paths - Coding Rooms
A relative path describes the location of a file relative to the current ... The Coding Rooms RUN button runs from the parent...
Read more >
How do you apply relative paths for locally developed HTML ...
What I did was to install a local development server such as EasyPHP, and setting the proper root folder within my project folder....
Read more >
8 Relative Path Best Practices - CLIMB
In this article, we will discuss 8 best practices for using relative paths in web development. We will also discuss why these best...
Read more >
What are the differences between absolute and relative paths?
The reason is that the path is the same no matter whether the instructions you provide start from the farthest region of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found