gatsby: --path-prefix doesn't work on gatsby develop

Description

Using gatsby-cli@1.1.28 I’m able to use gatsby develop --paths-prefix As of gatsby-cli@1.1.31 that throws Unknown argument: prefix-paths

It appears that changed in this PR: https://github.com/gatsbyjs/gatsby/pull/1969

Environment

Gatsby version: 1.1.28 Node.js version: 9.4.0 Operating System: macOS 10.13.2

Steps to reproduce

1. Use gatsby-cli@1.1.31

2. Set a pathPrefix in gatsby-config.js

3. Run gatsby develop --paths-prefix

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 13
  • Comments: 26 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Why is this issue closed? This is a perfectly valid requirement. I, for example, have another app that I would like to run under the same “domain”. That is, I would like to have an NGINX or similar in front of both apps and make Gatsby run under /blog, even during development.

We run our application on Docker Compose during development. User documentation is generated with Gatsby and the documentation is located in /docs. It seems that gatsby develop --paths-prefix does add the configured pathPrefix to all site paths, but not for /commons.js and /socket.io/socket.io.js paths:

commons.js                 404 NOT FOUND
/socket.io/socket.io.js    404 NOT FOUND

Is there an another setting that defines the commons.js and /socket.io/socket.io.js paths?

One usecase where this would come in really handy is if you have a multi app setup, where each app relies on another one, for example:

www.example.com // landing page www.example.com/login // auth service, same for all apps of the domain www.example.com/app // gatsby app that needs the credentials stored in local storage from the login app

This works quite nicely on a server, but you cant develop locally with it as you have no way to run gatsby under the app prefix

Still seems to be broken for me as well.

I am running into this issue myself. Has anyone found a way around it?

Agreed, this issue should be open. It is hard to debug a path-prefix issue if you can’t run it with path-prefix.

I agree, I’ve had issues as well, and would appreciate being able to develop with prefix enabled.

@rafael-nogueras I don’t have it on me anymore, I didn’t keep it because it didn’t solve our problem but it was small and went something like

export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
  const headComponents = getHeadComponents();
  headComponents.unshift('<base href="https://www.assetPrefix.com" />')
  replaceHeadComponents(headComponents)
}

hope this helps

I, too, am looking for path prefix to be added in development, and so far have not found a satisfactory solution (e.g. the one mentioned above seems to only work for the / path).

I tried implementing onCreatePage() in gatsby-node.js to replace all pages with ones where the path included the prefix path (only in development), but I ran into the following issues:

  • For some reason, onCreatePage() is not invoked for pages created manually in createPages() (even though I can see from console output that createPages() is invoked first), so I cannot prepend the path prefix on manually-created pages.
  • The <Link> component (and presumably navigate()) do not prepend the prefix path in development.
  • On a lark, I even tried adding the --prefix-paths flag to gatsby develop, to see if that would add the prefix path, but that for some reason seems to make the website hang.

Does anyone have any advice as to how to get this to work in development? Thanks! (I am using gatsby version 2.15.7, for the record).