Warm tip: This article is reproduced from serverfault.com, please click

Nuxt Heroku Deployment Problem, It uses localhost instead of the website url

发布于 2020-05-16 08:38:54

This is my first time deploying a nuxt app to heroku, I've followed the instructions I've found on nuxt guide.

Created the heroku app & added the following configuration:

enter image description here

added the procfile with the following line: web:nuxt start

enter image description here

And it worked, When I go to: https://coupongb-nuxt.herokuapp.com/ the website opened and the products are loaded but it seems the "infinit scrolling with uses $axios plugin isn't working, As well as opening a product page "by clicking a product card".

So I guess it's $axios that's making that error, Seems it's baseURL is localhost:3000 istead of the website domain enter image description here

So my question is How to make this.$axios.$get(...) point to the website domain instead of localhost:300

Questioner
smart design
Viewed
0
Tim Wickstrom 2020-05-16 17:06:36

You will need to set environment variables for this. https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

Where ever you are configuring Axios have it look at the environment variable to set the baseURL, example:

Axios.defaults.baseURL = process.env.APP_API

Then create your .env files in the root of your directory:

APP_API=https://coupongb-nuxt.herokuapp.com/

Alternatively you can change the baseurl inline whenever you are creating a call to your api. For example

this.$axios.get('/example-path')

would be replaced with

this.$axios({ url: '/example-path', baseURL: 'https://coupongb-nuxt.herokuapp.com' })