docusaurus: Error on development when changing baseUrl

Is this a bug report?

Yes

Have you read the Contributing Guidelines on issues?

Yes

Environment

Node: 8.9.1 Docusaurus: 1.1.1

(Docusaurus version via npm outdated docusaurus or yarn outdated docusaurus, OS, Node, npm, yarn)

Steps to Reproduce

I followed the step on setting your landing page: Docs landing Page. Which works well. However, the problem is when you change your baseUrl for deployment:

const siteConfig = {
  title: '<Project title>' /* title for your website */,
  tagline: '<Project tagline>',
  url: 'https://<org>.github.io' /* your website url */,
  baseUrl: '/<project>/' /* base url for your project */,
  // For github.io type URLs, you would set the url and baseUrl like:
  //   url: 'https://facebook.github.io',
  //   baseUrl: '/test-site/',

It works on build, but when I try to yarn start it gives me an error: screen shot 2018-05-24 at 12 38 11 am

If I put back the baseUrl: '/' it will work.

Workaround: make baseUrl: '/' when updating the doc and put back the baseUrl: '/project/' url when done.

Expected Behavior

It should redirect to my doc page as expected without switching baseUrl for development and production

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

hi @joshuaalpuerto, did you manage to resolve the issue ? Sorry for the delayed response. I just got the chance to look on this.

When you change your baseUrl to /project1/, this means that instead of localhost:3000, you should be able to access it at localhost:3000/project1

doc

Alright @joshuaalpuerto . I’m closing this issue for now as it seems it’s been working for you. Feel free to submit a PR on the improved redirect when you have the time.

@joshuaalpuerto I don’t own this repo but I believe that this repo is PR Friendly 👍 Feel free to submit one. No PR is too small if it’s useful.

I can give some advice though, that changes in your code might introduce a bug. What if my req.path is baseUrl/xxxx ? will it become baseUrl/baseUrl/xxx ? . Try testing the changes on Docusaurus with many test cases 😃

Thanks! Im actually checking the server.js now. Then I’ll get back once I figure this out. 😄

If you think improvement can be done & want to contribute, Feel free to submit a PR for it 😄 .

Adding this for your reference on where to modify https://github.com/facebook/Docusaurus/blob/b7be85843af2a07ead183dd8a467ebcf83e9a3e3/lib/server/server.js#L530-L533

@endiliey the code works

siteConfig.js

 const siteConfig = {
    ...
    baseUrl: '/project1/',
    ...
}

Then you have to change the redirect code from HTML as per docs:

From:

<!DOCTYPE HTML>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="0; url=docs/id-of-doc-to-land-on.html">
    <script type="text/javascript">
      window.location.href = 'docs/id-of-doc-to-land-on.html';
    </script>
    <title>Your Site Title Here</title>
  </head>
  <body>
    If you are not redirected automatically, follow this <a href="docs/id-of-doc-to-land-on.html">link</a>.
  </body>
</html>

To:

<!DOCTYPE HTML>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="0; url=/project1/docs/id-of-doc-to-land-on.html">
    <script type="text/javascript">
      window.location.href = '/project1/docs/id-of-doc-to-land-on.html';
    </script>
    <title>Your Site Title Here</title>
  </head>
  <body>
    If you are not redirected automatically, follow this <a href="/project1/docs/id-of-doc-to-land-on.html">link</a>.
  </body>
</html>

I will try this later and let you know! Thanks for your help!

I’m not the official maintainer of this repo, but that might be a good idea. It’s quite simple as well.

Quick implementation:

const siteConfig = require(CWD + '/siteConfig.js')
const host = `http://localhost:${port}${siteConfig.baseUrl}`;

instead of

https://github.com/facebook/Docusaurus/blob/b7be85843af2a07ead183dd8a467ebcf83e9a3e3/lib/start-server.js#L66