gridsome / gridsome

⚡️ The Jamstack framework for Vue.js
https://gridsome.org
MIT License
8.55k stars 489 forks source link

[question] image base url is still localhost for strapijs #1356

Open u007 opened 4 years ago

u007 commented 4 years ago

Description

duplicate https://gridsome.org/starters/gridsome-strapi-blog/ and tried to setup on production site but all images pointing to localhost:1337

even after setting up cloudinary and upload few images with the plugin, and saw the image on cloudinary, the build result for the frontend still resolve to localhost:1337

Steps to reproduce

add strapi plugin for cloudinary config/plugins.js

module.exports = ({ env }) => {
  const cloudinaryOption = {
    cloud_name: env('CLOUDINARY_CLOUD_NAME'),
    api_key: env('CLOUDINARY_KEY'),
    api_secret: env('CLOUDINARY_SECRET'),
  };
  // console.log("plugin", cloudinaryOption);
  return {
    // ...
    upload: {
      provider: 'cloudinary',
      providerOptions: cloudinaryOption,
    },
    // ...
  }
}

upload a image and replace both seo and image of one of the article to use uploaded image

npm run build and then deploy on fly.io

Expected result

images should point to cloudinary, even locally hosted image should point to backend url

Actual result

all pointing to localhost:1337

Environment

  System:
    OS: Linux 4.19 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  Binaries:
    Node: 12.18.4 - ~/.nvm/versions/node/v12.18.4/bin/node
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.4/bin/npm
  npmPackages:
    @gridsome/source-graphql: ^0.1.0 => 0.1.0
    gridsome: ^0.7.20 => 0.7.20
u007 commented 4 years ago

i know i could do this with GRIDSOME_STRAPI_URL, but do i do this when im building the site? when i use this on building, it will ask for data from production url, so i cannot load this locally?

u007 commented 4 years ago

and also , shouldnt cloudinary images be cloudinary url?

hjvedvik commented 4 years ago

@u007 It looks like you need to set a different GRIDSOME_STRAPI_URL for the production build. The starter is prefixing all absolute URLs with it here: ./frontend/src/utils/medias.js

u007 commented 4 years ago

thank you, i guess its all pointed back to strapijs means its strapijs own path issue right? otherwise i will need to upload all public/uploads files into a cdn and point it there...