saleor / saleor-storefront

A GraphQL-powered, NextJs-based, PWA storefront for Saleor. IMPORTANT: This project is [DEPRECATED] in favor of saleor/react-storefront soon to become our default demo and storefront starter pack.
https://demo.saleor.io/
BSD 3-Clause "New" or "Revised" License
770 stars 672 forks source link

build not using exported variables -or more variables needed?? #1013

Closed sourcesolver closed 3 years ago

sourcesolver commented 3 years ago

I am doing a node build of the storefront using 'npm run build:export'; before doing that,

I set exports:

API_URI=https://mysite:8000/graphql/ APP_MOUNT_URI=https://mysite:8000/dashboard/ STATIC_URL=https://mysite:8000/dashboard/ BACKEND_URL=https://mysite:8000/

It builds and generates content in a 'dist' subfolder. But the markup and JS generated appears to disregard my export directives and has references to 'localhost'

So in dist/index.html, I have for example:

Even if I modify that markup and load it into the web server, when running in the browser I get many "Failed to load resource: net::ERR_CONNECTION_REFUSED...http://localhost"; so I imagine there are still many references in the JS files to localhost -it's not building correctly.

How should I be setting those variables for the 'npm run build:export' to use them? I figured an "export var=..." before the build should suffice. Or are there other variables than the ones listed above that also need to be set??

null-ref-0000 commented 3 years ago

What version of saloer ?

krzysztofwolski commented 3 years ago

Seems to be something wrong in the way you do this, we regularly deploy storefront with changed API and works every time. If you are using version < 3.0, check if the issue still persists in 3.0.

sourcesolver commented 3 years ago

Found that the localhost was being set in a hidden file, '.env', used by your build. Why in the world would you not mention adjusting that in your instructions?!

https://docs.saleor.io/docs/2.9.0/getting-started/installation-linux/

krzysztofwolski commented 3 years ago

@sourcesolver You are linking outdated documentation (version 2.9) and using current master (version 3.0-alpha). Installation and configuration is in the README file:

Prerequisites

  • Node.js 14.16
  • A running instance of Saleor.

To run the storefront, you have to set the NEXT_PUBLIC_API_URI environment variable to point to the Saleor GraphQL API. If you are running Saleor locally, with the default settings, NEXT_PUBLIC_API_URI is set to: http://localhost:8000/graphql/. To change it, either create a .env.local file and add it there or set an env variable using export command.

Variables set in the environment should overwrite those set in .env file.

sourcesolver commented 3 years ago

Thanks very much for your help. I ended up using what turned up in google results.