New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird baseUrl when run generate #53

Closed
wi-cuckoo opened this Issue Aug 29, 2017 · 18 comments

Comments

Projects
None yet
5 participants
@wi-cuckoo

wi-cuckoo commented Aug 29, 2017

my nuxtent.config.js

module.exports = {
  content: [
    ['blog', {
      page: '/blog/_slug',
      permalink: "/:slug",
      generate: ['get', 'getAll'],
      isPost: false
    }]
  ],
  api: {
   	baseURL: process.env.NODE_ENV === 'production'
	    ? 'http://wi-cuckoo.io'
	    : 'http://localhost:3000'
 	}
}

my package.json scripts

"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "NODE_ENV=production nuxtent generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "precommit": "npm run lint"
  }

So When I run npm run generate. Why OPEN http://localhost:3000 ?

> cuckoo@1.0.0 generate /home/wi/bin/wi-cuckoo.gitpage
> NODE_ENV=production nuxtent generate

  nuxt:generate Generating... +0ms
[AXIOS] Base URL: http://wi-cuckoo.io/content-api , Browser: http://wi-cuckoo.io/_nuxt/content

 OPEN  http://localhost:3000

  nuxt:build App root: /home/wi/bin/wi-cuckoo.gitpage +0ms
This question is available on Nuxt.js community (#c52)
@STnetwork

This comment has been minimized.

STnetwork commented Aug 29, 2017

try it like that in your package.json :

"generate": "NODE_ENV='production' nuxtent generate",

@wi-cuckoo

This comment has been minimized.

wi-cuckoo commented Aug 29, 2017

@STnetwork Oh, that doesn't matter. I tried HOST=wi-cuckoo.io PORT=80 NODE_ENV=production nuxtent generate
although it can work, but should run as root to listen 80 port. No a good idea. Hope the developer can solve it

@STnetwork

This comment has been minimized.

STnetwork commented Aug 29, 2017

ok, it's strange because on the nuxtent-template, the behavior is different, there isn't OPEN http://localhost:3000

@alidcastano

This comment has been minimized.

Member

alidcastano commented Aug 29, 2017

What's the problem here exactly?

The OPEN http://localhost:3000 part I believe is the @nuxtjs/axios module which nuxtent configures so that the content can be easily fetched with the app.$content method.

You can change the url by configuring api.baseURL.

But I still don't get what the exact problem you're running into is. Do you just dislike seeing the incorrect log?

@wi-cuckoo

This comment has been minimized.

wi-cuckoo commented Aug 30, 2017

@alidcastano There is a bug in nuxtent when generate static files. In my config above, the *.json file requests in static page will go to http://localhost:3000. Maybe you could try generating static files by yourself and see what happened. If there is extra config to solve this bug, please update the doc. No any message in the project doc.

@alidcastano

This comment has been minimized.

Member

alidcastano commented Aug 31, 2017

Hey @wi-cuckoo I coincidently stumbled upon this problem today too #56 (if indeed we are referring to a similar issue).

The problem is that to generate the dynamic assets, we must run nuxt locally so that we can have access to content-api. Hence why it reads OPEN http://localhost:3000. Thus, this can't be avoided, but should not be causing any problems either. Can you verify this?

@wi-cuckoo

This comment has been minimized.

wi-cuckoo commented Sep 1, 2017

@alidcastano Okay. It's not a problem to OPEN http://localhost:3000. The problem is if I set don't set NODE_NEV = production. The request of some file in generated static files will be on localhost:3000. Absolutely that's incorrect, it should be the domain of production.

@STnetwork

This comment has been minimized.

STnetwork commented Sep 2, 2017

I had the same problem, even if you remove NODE_NEV = production, when you want nuxtent generate, it uses http://localhost:3000 the [AXIOS] Base URL, so how it would be possible to put a domain instead the localhost:3000 ?

@wi-cuckoo

This comment has been minimized.

wi-cuckoo commented Sep 2, 2017

@alidcastano There is still many problems. I suggest that you could build a demo with nuxt+nuxtent. and generate static files, then deloy it on github as git page. You'll understand what we encountered. If the road is OK, you can post it to our users to help solving.

@alidcastano

This comment has been minimized.

Member

alidcastano commented Sep 2, 2017

@wi-cuckoo @STnetwork so the site builds, correct? so are you experiencing problems when you deploy the site and try to fetch the content? I'll be fixing this either today or tomorrow so please let me know and be as specific as possible with the problem you are experiencing. And thanks again for using Nuxtent and helping get to the bottom of the early problems

I have a static site running with Nuxtent already, which is why I opened issue #56 as it was the only problem I encountered with my production flow

@wi-cuckoo

This comment has been minimized.

wi-cuckoo commented Sep 3, 2017

@alidcastano Thanks for you reply. May the former problems caused by the lack of document or my incorrect config. Now, I just encounter the problem #56 and #57. And maybe the #57 and #59 is just one problem. I encounter these both is generation.
The last, I hope the final correct example of how to deploy on GitHub

@STnetwork

This comment has been minimized.

STnetwork commented Sep 3, 2017

@alidcastano Why when you generate without NODE_ENV='production', it used the basic url axios to have access to the content-api like you said, and no the localhost:3000 automatically ?

Because when I generate with this nuxent.config :

const hljs = require('highlight.js')

module.exports = {
// content/HelloWorld.md --> posts/hello-world
 content: {
   page: '/_slug',
   permalink: ":slug",
    generate: [ // for static build
      'get', 'getAll'
    ],
   isPost: false
 },

  parsers: {
    md: {
      highlight: (code, lang) => {
        if (!(lang && hljs.getLanguage(lang))) return ''
        return hljs.highlight(lang, code, true).value
      }
    }
  },
	
  api: {
    baseURL: process.env.NODE_ENV === 'production'
      ? 'http://mydomain.com'
      : 'http://myipvps:3000'
  }
}

It cannot access to my BaseUrl for generate with the api-content with the NODE_ENV='production'.

When I do it whithout NODE_ENV='production', it works but it uses the wrong baseurl, it uses myipvps:3000 instead of mydomain.com, and I would like the baseurl with mydomain.com not my myipvps:3000.

I hope to be understood ^^

I think the problem is that at the end of the generate, it try to access to the content-api by the wrong way, instead to access by localhost:3000 or something you put in the package.json like "generate": "HOST=0.0.0.0 PORT=3000 IS_STATIC=true nuxtent generate", it try by the BaseUrl to access to the content-api it's not the good way.

@STnetwork

This comment has been minimized.

STnetwork commented Sep 6, 2017

EDIT 1 :

@alidcastano
Another thing you should see is when we re-actualize or go to a page static directly on a mardown file, it doesn't display the page it appears undefined.

You can see an example here : https://stnetworkbis.surge.sh/hello-world/

nuxtent config :

module.exports = {
  content: {
    permalink: ':slug',
    page: '/_content',
    generate: [ // for static build
      'get', 'getAll'
    ],
    isPost: false
  },

  api: {
    baseURL: process.env.NODE_ENV === 'production'
      ? 'https://stnetworkbis.surge.sh'
      : 'http://myipvps:3000'
  }
}

my package json :

{
  "name": "nuxtent",
  "version": "1.0.0",
  "description": "Nuxt.js Content Site",
  "author": "",
  "private": true,
  "dependencies": {
    "@nuxtjs/axios": "latest",
    "nuxt": "^1.0.0-rc8",
    "nuxtent": "latest"
  },
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "HOST=myipvps PORT=3000 NODE_ENV='production' IS_STATIC=true nuxtent generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "deploy": "push-dir --dir=dist --branch=gh-pages --cleanup",
    "precommit": "npm run lint"
  },
  "devDependencies": {
    "babel-eslint": "^7.1.1",
    "eslint": "^3.15.0",
    "eslint-config-standard": "^6.2.1",
    "eslint-loader": "^1.6.1",
    "eslint-plugin-html": "^2.0.0",
    "eslint-plugin-promise": "^3.4.1",
    "eslint-plugin-standard": "^2.0.1"
  }
}

EDIT 2 :

Did you find a solution about why it connects to the BaseUrl to access to the content-api during the generating instead of something we can put in the package.json like "HOST=0.0.0.0 PORT=3000 IS_STATIC=true nuxtent generate" ?
When I generate static with this nuxtent config :

module.exports = {
  content: {
    permalink: ':slug',
    page: '/_content',
    generate: [ // for static build
      'get', 'getAll'
    ],
    isPost: false
  },

  api: {
    baseURL: process.env.NODE_ENV === 'production'
      ? 'http://myipsvps:3000'
      : 'http://myipvps:3000'
  }
}

I have this result : https://stnetworkbistest.surge.sh/hello-world/

it works directly but not If I access to the page by the main page : https://stnetworkbistest.surge.sh/


EDIT 3 :

I found a temporary fix in the module.js of your module I changed :

browserBaseURL:a.baseURL+(process.env.STATIC?a.browserPrefix:a.serverPrefix)}]) by
browserBaseURL:(process.env.STATIC?a.browserPrefix:a.serverPrefix)}])

and I put my own browserPrefix:"https://stnetworkbistest.surge.sh/_nuxt/content"})}

BarryPH added a commit to callumflack/oceanblueboats that referenced this issue Sep 14, 2017

Hacky method to use different nuxtent baseUrl when generating and whe…
…n live

There is currently no method to use a different baseUrl when running nuxt generate and when running the static site
For more info: nuxt-community/nuxtent-module#53

Execution of a node script has been appended to the npm script 'generate'
The script replaces the developmentUrl with the productionUrl in the output static files
developmentUrl & productionUrl care defined in config/config.js
@suhogrozdje

This comment has been minimized.

Contributor

suhogrozdje commented Sep 17, 2017

I am also experiencing the same issue, BarryPH's hacky solution did the trick, but it indeed is hacky.

To make the issue clear in one paragraph: when running nuxtent generate, axios baseURL is set (by default) to http://localhost:3000/, which is good, but the problem emerges when one loads generated content in the browser: there, axios baseURL is still set to http://localhost:3000 instead of e.g. https://nuxtent.now.sh even if you set baseURL: process.env.NODE_ENV === 'production' ? 'http://localhost:3000' : 'https://nuxtent.now.sh' in nuxtent.config.js. This should not be so, because the generated content gets served on https://nuxtent.now.sh where localhost:3000 is not accessible, obviously.

Note that this problem only persists for generated sites and not when you use npm run build && npm run start.

May I ask why the baseURL is absolute? It seems to me that this problem wouldn't be present if you just left baseURL empty, making the whole path relative. I may be wrong bout that.

@suhogrozdje

This comment has been minimized.

Contributor

suhogrozdje commented Sep 17, 2017

For me, it works (as predicted) if I put this into nuxtent.config.js:

module.exports = {
  ...other stuff...
  api: {
    baseURL: ''
  }
}

So no BarryPH's workaround is needed. For the basic nuxtent user which is developing (and generating) on localhost:3000 and having static content hosted somewhere else, the solution to this problem is dead simple.

Maybe it would be worth changing api.baseURL in module.js to an empty string, so that those who generate their content don't be smashing their heads against the wall with this problem. 🤔

suhogrozdje pushed a commit to suhogrozdje/nuxtent-module that referenced this issue Sep 18, 2017

@STnetwork

This comment has been minimized.

STnetwork commented Sep 18, 2017

@suhogrozdje

Thanks for this solution it works well for me, I felt alone with this problem !

edit : the solution seems to work in yarn start and yarn dev but not in github pages, did you try it on github pages ?

I published with your solution on surge : http://stnetwork.surge.sh/

If you click on See Your First Post on the main page it works, but then at the page http://stnetwork.surge.sh/linux if you click again on See Your First Post it doesn't work, I have this message Request failed with status code 404.

@suhogrozdje

This comment has been minimized.

Contributor

suhogrozdje commented Sep 19, 2017

It works with Github Pages for me. But there are other problems I am experiencing, such as when i navigate directly to a post (i.e. refreshing when on it) and then navigating away from it, the content doesn't change. When I try then to refresh, it works again, but when I try to go back, it emits an error:

GET http://localhost:3000/_nuxt/content/articles/mathematics.whats-this-about..json 404 (Not Found)

Note the double dot, which probably means somewhere there is a string that is concatenated badly.

This plugin seems to be a bit laggy. I think those of us who feel up to the task should contribute to it by debugging their errors and making a pull request, as there seems to be too much work for the author, which is understandable.

@influx-agence

This comment has been minimized.

influx-agence commented Sep 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment